#include <bits/stdc++.h>
using namespace std;
string s[105];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int comp = 0;
  int prev = 0;
  for (int i = 0; i < m; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (s[j][i] == 'B') {
        flag = 1;
      }
    }
    if (flag == 0 && prev == 1) {
      comp++;
    }
    prev = flag;
  }
  if (prev == 1) {
    comp++;
  }
  cout << comp << endl;
  return 0;
}
