#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  string s;
  for (int i = 0; i < r; i++) cin >> s;
  s = s + ".";
  int count = 0;
  for (int i = 1; i <= c; i++)
    if (s[i] == '.' && s[i - 1] == 'B') count++;
  cout << count;
  return 0;
}
