#include <cstdio>

using namespace std;

#define N_MAX 100
#define M_MAX 100
#define INF '.'

int N, M;
char Field[N_MAX][M_MAX + 1] = {INF};

bool solve(int x, int y) {
	if(Field[x][y] == INF) return false;
    char tmp = Field[x][y];
    Field[x][y] = INF;

	int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
    int nx, ny;
    for(int i = 0; i < 4; i++) {
        nx = x + dx[i];
        ny = y + dy[i];
        if(nx < 0 || N <= nx || ny < 0 || M <= ny) continue;
    	if(Field[nx][ny] == tmp) solve(nx, ny);
    }
    return true;
}

int main(void) {
	int i, j;
	while(1) {
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
    	for(i = 0; i < N; i++) scanf("%s", Field[i]);
    	scanf("%d %d", &i, &j);
    	if(i != 0 && j != 0) return 1;
	
    	int count = 0;
    	for(i = 0; i < N; i++) {
        	for(j = 0; j < M; j++) {
            	if( solve(i, j) ) count++;
        	}
    	}
    	printf("%d", count);
		count = 0;
	}
    return 0;
}