//include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void dfs(int H, int W, char** field, int x, int y, char s);
void print_field(char** field, int H);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H,W;
  char** field;

  cin >> H >> W;

  field =(char**) malloc(sizeof(char*)*H);

  for(int i=0; i<H;i++){
      char* row = (char*)malloc(sizeof(char)*W);
      cin >> row;
      field[i] = row;
  }

  int zero, zero1;
  cin >> zero  >> zero1;

  int result = 0;

  for(int i=0; i < H; i++){
      for(int j=0; j < W; j++){

          if(field[i][j] == '#'){
              dfs(H, W, field, i, j, '#');
              result++;


          }else if(field[i][j] == '*'){
              dfs(H, W, field, i, j, '*');
              result++;

          }else if(field[i][j] == '@'){
              dfs(H, W, field, i, j, '@');
              result++;
          }
      }

      //print_field(field, H);
  }

  cout << result << endl;

  return 0;
}

void dfs(int H, int W, char** field, int x, int y, char s){

    field[x][y] = '.';

    int pattern[4][2]= { {-1,0}, {1,0}, {0,-1}, {0,1}};

    for(int i = 0; i<4; i++){
    
        int nx = x + pattern[i][0];
        int ny = y + pattern[i][1];
       
        if(0<=nx && nx < W && 0<=ny && ny < H && field[nx][ny]==s){
            dfs(H,W,field,nx,ny,s);
        }
    }

}

void print_field(char** field, int H){
    for(int i=0; i<H; i++){
        cout << field[i] << endl;
    }
    cout << "---------------------" <<endl;
}