#include <bits/stdc++.h>
using namespace std;
string s[105];
int id[100005];
int sz[100005];
int root(int x) {
  if (x == id[x]) return x;
  return id[x] = root(id[x]);
}
bool merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) return false;
  if (sz[x] >= sz[y])
    id[y] = x, sz[x] += sz[y];
  else
    id[x] = y, sz[y] += sz[x];
  return true;
}
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) id[i * m + j] = i * m + j, sz[i * m + j] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (s[i][j] == 'B' && s[nx][ny] == 'B') merge(i * m + j, nx * m + ny);
      }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == 'B' && root(i * m + j) == i * m + j) ans++;
  cout << ans << endl;
  return 0;
}
