#include<cstdio>
#include<cstring>
int record[82][52],c;
void dfs(int x,int y){
record[x][y]=0;
if(record[x-1][y]!=0)dfs(x-1,y);
if(record[x+1][y]!=0)dfs(x+1,y);
if(record[x][y+1]!=0)dfs(x,y+1);
if(record[x][y-1]!=0)dfs(x,y-1);
}
int main(){
int i,j,n,m;
scanf("%d%d",&m,&n);
memset(record,0,sizeof(record));
for(i=1;i<=m;i++)for(j=0;j<=n;j++){
scanf("%c",&c);
if(j==0)continue;
else {
record[i][j]=(int)(c-'0');
}
}
int ans=0;
for(i=1;i<=m;i++)for(j=1;j<=n;j++){
if(record[i][j]!=0){
ans++;
dfs(i,j);
}
}
printf("%d\n",ans);
return 0;
}