#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string str;
  while (n--) cin >> str;
  int cnt = 0, f = 0;
  for (int i = 0; i < m; i++) {
    if (str[i] == 'B' && !f) {
      cnt++;
      f = 1;
    } else if (str[i] == '.')
      f = 0;
  }
  cout << cnt << endl;
  return 0;
}
