#include <bits/stdc++.h>
using namespace std;
string s;
int n, m, ans = 0;
int main() {
  cin >> n >> m;
  while (n--) {
    cin >> s;
  }
  int flag = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'B') {
      flag = 1;
    } else if (flag) {
      flag = 0;
      ans++;
    }
  }
  cout << ans + flag << "\n";
  return 0;
}
