#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int qw[1001],qw1[1001];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int shu[101][101];
int x,y;
void show(int a,int b){
shu[a][b]=0;
int tx,ty;
int front=0,rear=1; int head,u; qw[1]=a; qw1[1]=b;
while(front<rear){
head=qw[++front];
u=qw1[front];
for(int i=0;i<4;i++){
tx=head+dx[i];
ty=u+dy[i];
if(tx>0&&tx<=x&&ty>0&&ty<=y&&shu[tx][ty]==1){
qw[++rear]=tx;
qw1[rear]=ty;
shu[tx][ty]=0;
}
}
}
}
int main(){
cin>>x>>y;
char ch;
for(int i=1;i<=x;i++)
for(int j=1;j<=y;j++){
cin>>ch;
if(ch=='0'){
shu[i][j]=0;
}
else shu[i][j]=1;
}
int top=0;
for(int i=1;i<=x;i++)
for(int j=1;j<=y;j++){
if(shu[i][j]==1){
top++;
show(i,j);
}
}
cout<<top<<endl;
return 0;
}