#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool b[m];
  for (int i = 0; i < m; i++) {
    b[i] = true;
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (b[j]) {
        if (s[j] == 'B') {
          b[j] = false;
        }
      }
    }
  }
  int count = 0;
  for (int k = 0; k < m; k++) {
    if (b[k] != b[k - 1]) {
      count++;
    }
  }
  if (b[0] == false) {
    count++;
  }
  if (b[m - 1] == false) {
    count++;
  }
  cout << count / 2 << endl;
  return 0;
}
