#include <bits/stdc++.h>
using namespace std;
int n, m;
int dx[5] = {1, -1, 0, 0};
int dy[5] = {0, 0, 1, -1};
int a[505][505];
int res;
char c;
void dfs (int i, int j) {
if(!a[i][j]){
a[i][j]=1;
}
for(int k=0;k<4;++k){
int xx=i+dx[k];
int yy=j+dy[k];
if(xx > 0 && xx <= n && yy > 0 && yy <= m && !a[xx][yy]){
dfs(xx, yy);
}
}
}
int main () {
cin >> n >> m;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
cin>>c;
if(c=='0'){
a[i][j]=0;
} else{
a[i][j]=1;
}
}
}
dfs(1,1);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if (!a[i][j]) {
res++;
}
}
}
cout <<res;
return 0;
}