#include <iostream>
#include <string>
using namespace std;
bool G[105][105];
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int n, m, cnt;
bool vis[105][105];
bool in(int x, int y) {
return 0 <= x && x < n && 0 <= y && y < m;
}
void dfs(int x, int y) {
if (vis[x][y] || !in(x, y) || !G[x][y]) {
return;
}
vis[x][y] = true;
for (int i = 0; i < 4; i++) {
dfs(x + dir[i][0], y + dir[i][1]);
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
G[i][j] = s[j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!vis[i][j]) {
dfs(i, j);
cnt++;
}
}
}
cout << cnt;
return 0;
}
全wa