#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, ans;
int g[N][N];
void dfs(int x, int y) {
if(g[x][y] == 0 || x < 1 || x > n || y < 1 || y > m) return;
g[x][y] = 0;
if(g[x + 1][y] != 0) dfs(x + 1, y);
if(g[x - 1][y] != 0) dfs(x - 1, y);
if(g[x][y + 1] != 0) dfs(x, y + 1);
if(g[x][y - 1] != 0) dfs(x, y - 1);
return;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
char c;
scanf("%c", &c);
g[i][j] = c - '0';
}
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
if(g[i][j] != 0) {
++ ans;
dfs(i, j);
}
}
}
cout<<ans;
return 0;
}
30pts