#include <bits/stdc++.h>
#define pb emplace_back
#define fir first
#define sec second
using i64 = long long;
using pii = std::pair<int, int>;
constexpr int maxn = 305;
int f[maxn][maxn][maxn << 1];
char s[maxn][maxn];
int n, m;
int main() {
freopen("copy.in", "r", stdin);
freopen("copy.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i)
scanf("%s", s[i] + 1);
memset(f, 0xcf, sizeof(f));
for (int i = 0; i <= n; ++i)
f[i][0][0] = 0;
for (int j = 0; j <= m; ++j)
f[0][j][0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
if (s[i][j] == '(')
f[i][j][1] = 1;
for (int k = 0; k <= n + m; ++k) {
if (s[i][j] == '(') {
if (!k) continue ;
f[i][j][k] = std::max(f[i - 1][j][k - 1], f[i][j - 1][k - 1]) + k;
} else {
f[i][j][k] = std::max(f[i - 1][j][k + 1], f[i][j - 1][k + 1]) + k;
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
ans = std::max(ans, f[i][j][0]);
printf("%d\n", ans);
return 0;
}