#include <cstdio>

#define N_MAX 100
#define M_MAX 100

int N, M;
char Field[N_MAX][M_MAX+1];

int main(void) {
    scanf("%d %d", &N, &M);
    int i, j;
    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(Field[i][j] != '.') {
                solve(i, j);
                count++;
            }
        }
    }
    printf("%d", count);
    return 0;
}

void solve(int x, int y) {
    char tmp = Field[x][y];
    Field[x][y] = '.';

    int nx, ny;
    for(int i = -1; i <= 1; i++) {
        for(int j =-1; j<= 1; j++) {
            nx = x + i;
            ny = y + i;
            if(0 <= nx && nx < N && 0<= ny && ny < M && Field[nx][ny] == tmp) {
                solve(nx, ny);
            }
        }
    }
    return;
}