// Arup Guha
// 2/6/2024
// Soluion to COP 3503 Exam 1 Question 9

import java.util.*;

public class connected {

	public static int r;
	public static int c;
	public static char[][] g;
	
	final public static int[] DX = {0,1};
	final public static int[] DY = {1,0};
	
	public static void main(String[] args) {
		
		// Read in grid.
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		g = new char[r][];
		for (int i=0; i<r; i++)
			g[i] = stdin.next().toCharArray();
			
		// Create disjoint set.
		djset dj = new djset(r*c);
		
		// Go to each square.
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
				
				// Go in two "forward" directions from here.
				for (int k=0; k<2; k++) {
					
					// Calculate adjacent neighbor.
					int nx = i + DX[k];
					int ny = j + DY[k];
					
					// Out of bounds...
					if (nx>=r || ny>=c) continue;
					
					// Put together in same group if these two are the same letter.
					if (g[i][j] == g[nx][ny])
						dj.union(i*c+j, nx*c+ny);
				}
			}
		}

		// Ta da!
		System.out.println(dj.numSets);
	}
}

/*** Usual disjoint set class ***/
class djset {

	public int[] par;
	public int numSets;
	
	public djset(int n) {
		par = new int[n];
		for (int i=0; i<n; i++) par[i] = i;
		numSets = n;
	}
	
	public int find(int u) {
		if (par[u] == u) return u;
		return par[u] = find(par[u]);
	}
	
	public boolean union(int u, int v) {
		u = find(u);
		v = find(v);
		
		if (u == v) return false;
		
		numSets--;
		par[v] = u;
		return true;
	}
}