#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, ans, tt;
char a[N][N];
int dir[4][6] = {{0, 0, 1, 0, 0, 1}, {0, 0, -1, 0, 0, -1},
{0, 0, -1, 0, 0, 1}, {0, 0, 1, 0, 0, -1}};
int main() {
freopen("cover.in", "r", stdin);
freopen("cover.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == '1') tt++;
}
}
int minn = 1e9;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = 0; k < 4; k++) {
int dx = i + dir[k][0], dy = j + dir[k][1];
int dx1 = i + dir[k][2], dy1 = j + dir[k][3];
int dx2 = i + dir[k][4], dy2 = j + dir[k][5];
if (dx >= 1 && dx <= n && dy >= 1 && dy <= m && dx1 >= 1 && dx1 <= n && dy1 >= 1 && dy1 <= m && dx2 >= 1 && dx2 <= n && dy2 >= 1 && dy2 <= m) {
int res = 0;
if (a[dx][dy] == '1') res++;
if (a[dx1][dy1] == '1') res++;
if (a[dx2][dy2] == '1') res++;
if (res < minn && res) {
minn = res;
}
}
}
}
}
// minn 则为第一次 L 形最少覆盖 1 的数量,tt为矩形中 1 的数量,以下结论则显然推出
cout << tt - minn + 1 << endl;
}