#include <cstdio>
#include <fstream>
#include <iostream>
using namespace std;
int x,y;
void counting(int i,int j,char castle[101][101])
{
if(i!=(x-1))
{
if(castle[i+1][j]=='0')
{
castle[i+1][j]='$';
counting(i+1,j,castle);
}
}
if(i!=0)
{
if(castle[i-1][j]=='0')
{
castle[i-1][j]='$';
counting(i-1,j,castle);
}
}
if(j!=(y-1))
{
if(castle[i][j+1]=='0')
{
castle[i][j+1]='$';
counting(i,j+1,castle);
}
}
if(j!=0)
{
if(castle[i][j-1]=='0')
{
castle[i][j-1]='$';
counting(i,j-1,castle);
}
}
}
int main()
{
int rooms =0;//number of rooms
char castle[101][101]={}; //but we use only from 0 to x-1 and from 0 to y-1
ifstream read("input.txt");
ofstream write("output.txt");
read>>x>>y;
for(int i=0;i<y;i++) read>>castle[i];//reading the map
for(int i=0;i<=x;i++)
{
for(int j=0;j<=y;j++)
{
if(castle[i][j]=='0')
{
bool unc = true;
if(i!=(x-1))
{
//check x+1,y
if(castle[i+1][j]=='$') unc=false;
}
if(i!=0)
{
//check x-1,y
if(castle[i-1][j]=='$') unc=false;
}
if(j!=(y-1))
{
//check x,y+1
if(castle[i][j+1]=='$') unc=false;
}
if(j!=0)
{
//check x,y-1
if(castle[i][j-1]=='$') unc=false;
}
if(unc)
{
rooms++;
counting(i,j,castle);
}
castle[i][j]='$'; //dollar sign indicates a counted room
}//end of first if
}//end of second for
}//end of first for
write<<rooms;
return 0;
}