#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  long long int R, C;
  cin >> R >> C;
  string str;
  getline(cin, str);
  for (long long int r = 0; r < R; ++r) getline(cin, str);
  long long int res = 0;
  for (long long int c = 0; c < C; ++c) {
    if (str[c] == 'B' && (!c || str[c - 1] == '.')) ++res;
  }
  printf("%lli\n", res);
  return 0;
}
