#include <bits/stdc++.h>
using namespace std;
const char empty{'.'};
int count(int p_x, int p_y, char p_col, int x, int y, vector<string>& grid) {
  int ret = 0;
  if (grid[p_y][p_x] == p_col) {
    ++ret;
    grid[p_y][p_x] = empty;
    if (p_y + 1 < y && grid[p_y + 1][p_x] != empty)
      ret += count(p_x, p_y + 1, p_col, x, y, grid);
    if (p_x + 1 < x && grid[p_y][p_x + 1] != empty)
      ret += count(p_x + 1, p_y, p_col, x, y, grid);
    if (p_y - 1 >= 0 && grid[p_y - 1][p_x] != empty)
      ret += count(p_x, p_y - 1, p_col, x, y, grid);
    if (p_x - 1 >= 0 && grid[p_y][p_x - 1] != empty)
      ret += count(p_x - 1, p_y, p_col, x, y, grid);
  }
  return ret;
}
void countBlocks(int x, int y, int color, vector<string>& grid) {
  int nbr_blocks = 0;
  for (int p_y = 0; p_y < y; ++p_y) {
    for (int p_x = 0; p_x < x; ++p_x) {
      char p_col = grid[p_y][p_x];
      if (p_col != empty) {
        int squares_count = count(p_x, p_y, p_col, x, y, grid);
        if (squares_count > 0) nbr_blocks += 1;
      }
    }
  }
  cout << nbr_blocks;
}
int main(void) {
  int x, y;
  cin >> y >> x;
  vector<string> grid;
  for (int i = 0; i < y; i++) {
    string s;
    cin >> s;
    grid.push_back(s);
  }
  countBlocks(x, y, 0, grid);
  return 0;
}
