#include<iostream>


using namespace std;

int xx[] = {-1,0,1,0}, yy[] = {0,1,0,-1};
int ans = 0, vir[10][10],orgVir[10][10];
int N, M;

void countVir() {
	int tmp = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			if (vir[i][j] == 0)
				tmp += 1;
	ans = max(ans, tmp);
}
void copyVir() {
	for(int i=0;i<N;i++)
		for (int j = 0; j < M; j++) {
			orgVir[i][j] = vir[i][j];
		}
}
void copyOrg() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			vir[i][j] = orgVir[i][j];
		}
}
void func(int x, int y) {			// 바이러스 전파
	if (x < 0 || y < 0 || x >= N || y >= M) return;
	if (vir[x][y] == 2) {
		for (int i = 0; i < 4; i++) {
			if ((x + xx[i] >= 0 && y + yy[i] >= 0 && x + xx[i] < N && y + yy[i] < M) && vir[x + xx[i]][y + yy[i]] == 0) {
				vir[x + xx[i]][y + yy[i]] = 2;
				func(x + xx[i], y + yy[i]);
			}
		}
	}
	if (y == M - 1) func(x + 1, 0);
	else func(x, y + 1);
}

void wall(int x,int y,int count) {		// 벽 설치
	if (x < 0 || y < 0 || x >= N || y >= M) return;
	if (count == 3) {
		copyVir();
		func(0, 0);
		countVir();
		copyOrg();
		return;
	}
	if (vir[x][y] == 0) {
		int tmpx, tmpy;
		if (y == M - 1) {
			tmpx = x + 1; tmpy = 0;
		}
		else {
			tmpx = x; tmpy = y+1;
		}
		wall(tmpx, tmpy, count);
		vir[x][y] = 1;
		wall(tmpx, tmpy, count+1);
		vir[x][y] = 0;
	}
	else {
		if (y == M - 1)
			wall(x + 1, 0, count);
		else
			wall(x, y + 1, count);
	}
}
int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> N >> M;
	for(int i=0;i<N;i++)
		for (int j = 0; j < M; j++) {
			int tmp;
			cin >> tmp;
			vir[i][j] = tmp;
		}
	wall(0, 0, 0);
	cout << ans;
}
