#include using namespace std; #define x first #define y second typedef pair PII; const int N = 110; int g[N][N]; int n, m; int dx[] = {-1, 0, 1, 0}; //上右下左 int dy[] = {0, 1, 0, -1}; //上右下左 int ans; queue q; void bfs() { while (q.size()) { auto u = q.front(); q.pop(); for (int i = 0; i < 4; i++) { int tx = u.x + dx[i], ty = u.y + dy[i]; if (g[tx][ty]) { g[tx][ty] = 0; q.push({tx, ty}); } } } } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> g[i][j]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (g[i][j]) { ans++; g[i][j] = 0; q.push({i, j}); bfs(); } } } printf("%d", ans); return 0; }