#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  string *str = new string[r];
  for (int i = 0; i < r; i++) {
    cin >> str[i];
  }
  int counter = 0;
  bool wall_exist = false;
  for (int p = 0; p < c; p++) {
    if (str[r - 1].at(p) == '.' && wall_exist) {
      counter++;
      wall_exist = false;
    }
    if (str[r - 1].at(p) == 'B') wall_exist = true;
  }
  if (wall_exist) counter++;
  cout << counter;
  return 0;
}
