#include <bits/stdc++.h>
using namespace std;
int num = 0;
void open(vector<string> wall, vector<vector<int>>& check, int i, int j, int R,
          int C) {
  if (0 < i && i <= R && 0 < j && j <= C && !check[i][j] &&
      wall[i][j - 1] == 'B') {
    check[i][j] = num;
    open(wall, check, i + 1, j, R, C);
    open(wall, check, i - 1, j, R, C);
    open(wall, check, i, j + 1, R, C);
    open(wall, check, i, j - 1, R, C);
  }
}
int main() {
  int R, C;
  cin >> R >> C;
  vector<string> wall(R + 1);
  for (int i = 1; i <= R; i++) {
    cin >> wall[i];
  }
  vector<vector<int>> check(R + 1, vector<int>(C + 1, 0));
  for (int i = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      if (!check[i][j] && wall[i][j - 1] == 'B') {
        num++;
        open(wall, check, i, j, R, C);
      }
    }
  }
  cout << num;
  return 0;
}
