#include <iostream>
using namespace std;
int a[102][102];
void fill(int i, int j, int c)
{
a[i][j] = c;
if(a[i-1][j] == 1)
fill(i-1, j, c);
if(a[i][j+1] == 1)
fill(i, j+1, c);
if(a[i+1][j] == 1)
fill(i+1, j, c);
if(a[i][j-1] == 1)
fill(i, j-1, c);
}
int main()
{
int n, m, c = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <=m; j++)
cin >> a[i][j];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
if(a[i][j] == 1)
{
c++;
fill(i, j, c + 1);
}
cout << c;
return 0;
}