#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 101
#define max_m 50
#define max_w 1000
#define max_h 1000
#define max_k 10000
#define max_l 10000
#define INF 9999999

typedef long long lint;

char field[max_h][max_w];

void dfs(int i,int j){
    char check=field[i][j];
    field[i][j]='.';
    if(field[i-1][j]==check){
        dfs(i-1,j);
    }
    if(field[i+1][j]==check){
        dfs(i+1,j);
    }
    if(field[i][j-1]==check){
        dfs(i,j-1);
    }
    if(field[i][j+1]==check){
        dfs(i,j+1);
    }
    return ;
    
}

int main()
{
    int h,w;
    int count=0;
    cin>>h>>w;
    
    for(int i=0;i<h;i++)cin>>field[i];
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            
            if(field[i][j]!='.'){
                dfs(i,j);
                count++;
            }
        }
    }
    int a,b;
    cin>>a>>b;
    printf("%d\n",count);
    return 0;
}