#include <iostream> using namespace std; int n, m; int X[4] = {0, 0, 1, -1}; int Y[4] = {1, -1, 0, 0}; int map[1000][1000]; bool vis[1000][1000] = {false};
bool judge(int a, int b) { if (a > n || b > m || a < 0 || b < 0) return false; //越界 return true; } int DFS(int x, int y) { if (!judge(x, y)) return 0; //越界 vis[x][y] = true; //标记为访问 for (int i = 0; i < 4; i++) { int newx = x + X[i]; int newy = y + Y[i]; if (!vis[newx][newy] && map[x][y] == map[newx][newy]) DFS(newx, newy); } return 0; } int main() { int ans; while (cin >> n >> m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> map[i][j]; } } ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (!vis[i][j]) { ans++; DFS(i, j); } } } cout << ans << endl; } return 0; }