#include <bits/stdc++.h>
using namespace std;
long long int r, c;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> r >> c;
  while (r--) cin >> s;
  long long int ans = 0;
  for (long long int i = 0; i <= c - 1; ++i) {
    if (s[i] != 'B') continue;
    ans++;
    while (i <= c - 1 && s[i] == 'B') i++;
  }
  cout << ans;
}
