#include <bits/stdc++.h>
using namespace std;
const int o = 1000000009;
int main() {
  int r, c, count = 0;
  char prom;
  cin >> r >> c;
  char arr[100][100];
  bool boo[100][100];
  deque<pair<int, int>> wall;
  pair<int, int> curr;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> arr[i][j];
      boo[i][j] = false;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (arr[i][j] == 'B' && !boo[i][j]) {
        wall.push_back(make_pair(i, j));
        boo[i][j] = true;
        while (!wall.empty()) {
          curr = wall.front();
          wall.pop_front();
          if (curr.first - 1 >= 0 && !boo[curr.first - 1][curr.second] &&
              arr[curr.first - 1][curr.second] == 'B') {
            wall.push_back(make_pair(curr.first - 1, curr.second));
            boo[curr.first - 1][curr.second] = true;
          }
          if (curr.first + 1 < r && !boo[curr.first + 1][curr.second] &&
              arr[curr.first + 1][curr.second] == 'B') {
            wall.push_back(make_pair(curr.first + 1, curr.second));
            boo[curr.first + 1][curr.second] = true;
          }
          if (curr.second + 1 < c && !boo[curr.first][curr.second + 1] &&
              arr[curr.first][curr.second + 1] == 'B') {
            wall.push_back(make_pair(curr.first, curr.second + 1));
            boo[curr.first][curr.second + 1] = true;
          }
          if (curr.second - 1 >= 0 && !boo[curr.first][curr.second - 1] &&
              arr[curr.first][curr.second - 1] == 'B') {
            wall.push_back(make_pair(curr.first, curr.second - 1));
            boo[curr.first][curr.second - 1] = true;
          }
        }
        count++;
      }
    }
  }
  cout << count;
  cin >> c;
}
