import java.util.Scanner;
public class Main {
public static int N, M, result = 0;
public static char[][] graph;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args){
N = sc.nextInt();
M = sc.nextInt();
graph = new char[N][M];
for (int i = 0;i < N;i++){
graph[i] = sc.next().toCharArray();
}
for (int i = 0;i < N;i++){
for (int j = 0;j < M;j++){
if (graph[i][j] != '0'){
result ++;
dfs(i, j, graph[i][j]);
}
}
}
System.out.println(result);
sc.close();
}
public static void dfs(int i, int j, char ch) {
int[] dx = {0,0,-1,1};
int[] dy = {1,-1,0,0};
graph[i][j] = '0';
for (int k = 0;k < 4;k++){
int x = dx[k] + i;
int y = dy[k] + j;
if (x >= 0 && x < N && y >= 0 && y < M && graph[x][y] == ch){
dfs(x, y, ch);
}
}
}
}