#include <bits/stdc++.h>
using namespace std;
int main() {
  int R, C;
  cin >> R >> C;
  string l;
  for (int i = 0; i < R; ++i) {
    cin >> l;
  }
  int segments = 0;
  l.insert(l.begin(), '.');
  l.push_back('.');
  char lc = l.front();
  for (char c : l) {
    if (lc == '.' && c == 'B') {
      ++segments;
    }
    lc = c;
  }
  cout << segments << endl;
  return 0;
}
