#include <bits/stdc++.h>
using namespace std;
long double pi = 3.1415926536;
int main() {
  int r, c;
  cin >> r >> c;
  vector<string> w(r);
  for (int i = 0; i < r; ++i) cin >> w[i];
  int k = 0, res = 0;
  while (k < c) {
    if (w[r - 1][k] == 'B') {
      res++;
      while (k < c && w[r - 1][k++] == 'B')
        ;
    } else
      k++;
  }
  cout << res;
}
