#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 10;
string S[111];
int r, c;
int main() {
  cin >> r >> c;
  for (int i = 0; i < r; i++) cin >> S[i];
  int res = 0;
  char prev = S[r - 1][0];
  if (prev == 'B') res++;
  for (int i = 1; i < c; i++) {
    if (prev != S[r - 1][i]) {
      if (S[r - 1][i] == 'B') {
        res++;
      }
      prev = S[r - 1][i];
    }
  }
  cout << res << endl;
  return 0;
}
