#include <bits/stdc++.h>
using namespace std;
int ans;
int n, m;
string s;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s;
  for (int i = 0; i <= m - 1; i++) {
    bool ok = 0;
    while (i < m && s[i] == 'B') ok = 1, i++;
    ans += ok;
  }
  cout << ans;
}
