#include <bits/stdc++.h>
using namespace std;
int a[105][105], n, m;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void bfstowhite(int x, int y)
{
for (int i = 0; i < 4; i++)
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx >= 0 && xx < n && yy >= 0 && yy < m)
if (a[xx][yy] == 1)
{
a[xx][yy] = 0;
bfstowhite(xx, yy);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == 1)
{
ans++;
a[i][j] = 0;
bfstowhite(i, j);
}
cout << ans;
return 0;
}