#include <bits/stdc++.h>
using namespace std;
const double Pi = 3.1415926536;
int main() {
  int r, c;
  cin >> r >> c;
  string s;
  for (int i = 0; i < r; ++i) {
    cin >> s;
  }
  int res = 0;
  bool f = false;
  for (int i = 0; i < c; ++i) {
    if (s[i] == 'B' && f == false) {
      f = true;
      ++res;
    }
    if (s[i] == '.' && f) f = false;
  }
  cout << res << endl;
  return 0;
}
