#include <iostream>
#include <vector>
#pragma GCC optimize ("Ofast")
using namespace std;
int rows,cols;
int ans=0;
int area;
inline bool controlla(vector<vector<int>>&m,int i,int j){
if(m[i][j])
return false;
if(i>=2){
if(m[i-1][j]&&m[i-2][j])
return false;
if(j>=2){
if(m[i-1][j-1]&&m[i-2][j-2])
return false;
}
if(j<=cols-3){
if(m[i-2][j+2]&&m[i-1][j+1])
return false;
}
}
if(i<=rows-3){
if(m[i+1][j]&&m[i+2][j])
return false;
if(j>=2){
if(m[i+1][j-1]&&m[i+2][j-2])
return false;
}
if(j<=cols-3){
if(m[i+1][j+1]&&m[i+2][j+2])
return false;
}
}
if(j>=2){
if(m[i][j-1]&&m[i][j-2])
return false;
}
if(j<=cols-3){
if(m[i][j+1]&&m[i][j+2])
return false;
}
if(j>0 && j<cols-1){
if(m[i][j-1]&&m[i][j+1])
return false;
}
if(i>0 && i<rows-1){
if(m[i-1][j]&&m[i+1][j])
return false;
}
if(j>0 && i>0 && j<cols-1 && i<rows-1){
if(m[i-1][j-1]&&m[i+1][j+1])
return false;
if(m[i-1][j+1]&&m[i+1][j-1])
return false;
}
return true;
}
void solve(vector<vector<int>>&m,int count,int i,int j){
if(j>=cols){
i++;
j=0;
}
if(i==rows){
if(count>ans)
ans=count;
return;
}
if((area-((i)*cols+j)+count)<=ans)
return;
if(controlla(m,i,j)){
m[i][j]=1;
solve(m,count+1,i,j+1);
m[i][j]=0;
}
solve(m,count,i,j+1);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>rows>>cols;
vector<vector<int>>m(rows,vector<int>(cols));
area=rows*cols;
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
cin>>m[i][j];
solve(m,0,0,0);
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojcHJhZ21hIEdDQyBvcHRpbWl6ZSAoIk9mYXN0IikKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCByb3dzLGNvbHM7CmludCBhbnM9MDsKaW50IGFyZWE7CgppbmxpbmUgYm9vbCBjb250cm9sbGEodmVjdG9yPHZlY3RvcjxpbnQ+PiZtLGludCBpLGludCBqKXsKICAgIGlmKG1baV1bal0pCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgaWYoaT49Mil7CiAgICAgICAgaWYobVtpLTFdW2pdJiZtW2ktMl1bal0pCiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICBpZihqPj0yKXsKICAgICAgICAgICAgaWYobVtpLTFdW2otMV0mJm1baS0yXVtqLTJdKQogICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBpZihqPD1jb2xzLTMpewogICAgICAgICAgICBpZihtW2ktMl1baisyXSYmbVtpLTFdW2orMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgfQogICAgaWYoaTw9cm93cy0zKXsKICAgICAgICBpZihtW2krMV1bal0mJm1baSsyXVtqXSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmKGo+PTIpewogICAgICAgICAgICBpZihtW2krMV1bai0xXSYmbVtpKzJdW2otMl0pCiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGlmKGo8PWNvbHMtMyl7CiAgICAgICAgICAgIGlmKG1baSsxXVtqKzFdJiZtW2krMl1baisyXSkKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICB9CiAgICBpZihqPj0yKXsKICAgICAgICBpZihtW2ldW2otMV0mJm1baV1bai0yXSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgaWYoajw9Y29scy0zKXsKICAgICAgICBpZihtW2ldW2orMV0mJm1baV1baisyXSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgaWYoaj4wICYmIGo8Y29scy0xKXsKICAgICAgICBpZihtW2ldW2otMV0mJm1baV1baisxXSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgaWYoaT4wICYmIGk8cm93cy0xKXsKICAgICAgICBpZihtW2ktMV1bal0mJm1baSsxXVtqXSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgaWYoaj4wICYmIGk+MCAmJiBqPGNvbHMtMSAmJiBpPHJvd3MtMSl7CiAgICAgICAgaWYobVtpLTFdW2otMV0mJm1baSsxXVtqKzFdKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYobVtpLTFdW2orMV0mJm1baSsxXVtqLTFdKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CgogICAgcmV0dXJuIHRydWU7Cn0KCgp2b2lkIHNvbHZlKHZlY3Rvcjx2ZWN0b3I8aW50Pj4mbSxpbnQgY291bnQsaW50IGksaW50IGopewogICAgaWYoaj49Y29scyl7CiAgICAgICAgaSsrOwogICAgICAgIGo9MDsKICAgIH0KICAgIGlmKGk9PXJvd3MpewogICAgICAgIGlmKGNvdW50PmFucykKICAgICAgICAgICAgYW5zPWNvdW50OwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGlmKChhcmVhLSgoaSkqY29scytqKStjb3VudCk8PWFucykKCQlyZXR1cm47CQogICAgaWYoY29udHJvbGxhKG0saSxqKSl7CiAgICAgICAgbVtpXVtqXT0xOwogICAgICAgIHNvbHZlKG0sY291bnQrMSxpLGorMSk7CiAgICAgICAgbVtpXVtqXT0wOwogICAgfQogICAgc29sdmUobSxjb3VudCxpLGorMSk7Cn0KCmludCBtYWluKCl7Cmlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKY2luLnRpZSgwKTsKICAgIGNpbj4+cm93cz4+Y29sczsKdmVjdG9yPHZlY3RvcjxpbnQ+Pm0ocm93cyx2ZWN0b3I8aW50Pihjb2xzKSk7CiAgICBhcmVhPXJvd3MqY29sczsKICAgIGZvcihpbnQgaT0wO2k8cm93cztpKyspCiAgICAgICAgZm9yKGludCBqPTA7ajxjb2xzO2orKykKICAgICAgICAgICAgY2luPj5tW2ldW2pdOwoKICAgIHNvbHZlKG0sMCwwLDApOwoKICAgIGNvdXQ8PGFuczsKCiAgICByZXR1cm4gMDsKfQo=