#include <bits/stdc++.h>
using namespace std;
char ch;
int r, c, nx, ny, ax[] = {1, -1, 0, 0}, ay[] = {0, 0, 1, -1}, ans = 0;
bool mp[55][55];
void dfs(int x, int y){
mp[x][y] = 0;
for (int i = 0; i < 4; i++){
nx = x + ax[i], ny = y + ay[i];
if (!mp[nx][ny] || nx <= -1 || ny <= -1 || nx >= r || ny >= c) continue;
dfs(nx, ny);
}
}
int main(){
scanf("%d %d", &r, &c);
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
cin >> ch;
mp[i][j] = ch - '0';
}
}
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
if (mp[i][j]){
dfs(i, j);
ans++;
}
}
}
printf("%d\n", ans);
return 0;
}