#include <bits/stdc++.h>
using namespace std;
char c[45][45];
long long par[111111], siz[111111], n, m;
long long dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void init(long long x) {
  for (long long i = 0; i < x; i++) {
    par[i] = i;
    siz[i] = 1;
  }
}
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
void unite(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (siz[x] < siz[y]) {
    par[x] = y;
    siz[y] += siz[x];
  } else {
    par[y] = x;
    siz[x] += siz[y];
  }
}
bool same(long long x, long long y) { return find(x) == find(y); }
long long Size(long long f) { return siz[find(f)]; }
map<pair<long long, long long>, bool> mp;
signed main() {
  cin >> n >> m;
  init(n * m);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      for (long long k = 0; k < 4; k++) {
        long long x = i + dx[k];
        long long y = j + dy[k];
        if (c[i][j] == c[x][y] && c[i][j] == '.')
          unite((i - 1) * m + j, x * m + y);
      }
    }
  }
}
