#include <bits/stdc++.h>
using namespace std;
const int N = 305, M = 303;
int n, m, f[N][N][N];
char s[N][N];
int main () {
freopen("copy.in","r", stdin);
freopen("copy.out", "w", stdout);
memset(f, -0x3f, sizeof(f));
cin >> n >> m;
for (int i = 1;i <= n;i++) cin >> (s[i]+1);
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
for (int z = 0;z <= 300;z++) {
if (s[i][j] == '(') {
if (z) f[i][j][z] = max(f[i-1][j][z-1], f[i][j-1][z-1])-(i+j-1);
}
else f[i][j][z] = max(f[i-1][j][z+1], f[i][j-1][z+1])+i+j-1;
}
if (s[i][j] == '(') f[i][j][1] = max(f[i][j][1], -i-j+1);
}
}
int ans = 0;
for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) ans = max(ans, f[i][j][0]);
cout << ans;
return 0;
}