#include <bits/stdc++.h>
using namespace std;
int cnt(0), comp[102][102];
bool field[102][102];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void dfs(int x, int y) {
  comp[x][y] = cnt;
  for (int i(0); i < 4; ++i)
    if (field[x + dx[i]][y + dy[i]] && !comp[x + dx[i]][y + dy[i]])
      dfs(x + dx[i], y + dy[i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  char ch;
  int c, r;
  cin >> r >> c;
  for (int i(1); i <= r; ++i)
    for (int j(1); j <= c; ++j) {
      cin >> ch;
      field[i][j] = ch == 'B';
    }
  for (int i(1); i <= r; ++i)
    for (int j(1); j <= c; ++j)
      if (!comp[i][j] && field[i][j]) {
        ++cnt;
        dfs(i, j);
      }
  cout << cnt;
}
