#include <bits/stdc++.h>
using namespace std;
int main() {
  char str[1111];
  int r, c, count = 0;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> str[j];
    }
  }
  c++;
  for (int i = 0; i < c - 1; i++) {
    if (str[i] == 'B' and str[i + 1] != 'B') count++;
  }
  cout << count;
}
