#include <bits/stdc++.h>
using namespace std;
vector<string> grid;
int main() {
  int r, c;
  scanf("%d %d", &r, &c);
  string str;
  for (int i = 0; i < r; i++) {
    cin >> str;
    grid.push_back(str);
  }
  int cnt = 0;
  bool flag = false;
  for (int i = 0; i < c; i++) {
    if (grid[r - 1][i] == 'B') {
      flag = true;
    }
    if (flag && grid[r - 1][i] == '.') {
      flag = false;
      cnt++;
    }
  }
  if (flag) cnt++;
  printf("%d", cnt);
}
