#include<bits/stdc++.h>
using namespace std;
int map1[110][110],n,m,ans=0;
int fx[4]={-1,1,0,0};
int fy[4]={0,0,1,-1};
bool mapf[110][110];
struct Node {
int x, y;
};
memset(mapf,false,sizeof(mapf) );
void bfs(int n, int m) {
queue<Node> q;
q.push({n, m});
mapf[n][m] = true;
while (q.size()) {
Node t = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int a = t.x + fx[i], b = t.y + fy[i];
if (a < 0 || a >= n || b < 0 || b >= m) continue;
if (mapf[a][b]) continue;
if (map1[a][b]==0) continue;
q.push({a, b});
mapf[a][b] = true;
}
}
ans++;
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>map1[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(map1[i][j]!=0&&!mapf[i][j]){
bfs(i,j);
}
}
}
cout<<ans;
return 0;
}