#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  vector<string> wall(r);
  for (int i = 0; i < r; ++i) {
    cin >> wall[i];
  }
  int result = 0;
  for (int i = 0, clen = 0; i <= c; ++i) {
    if (clen && (i == c || wall[r - 1][i] == '.')) {
      clen = 0;
      ++result;
    } else if (wall[r - 1][i] == 'B') {
      ++clen;
    }
  }
  cout << result << endl;
}
