#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, len, i, ans = 0, a = 0;
  cin >> n >> len;
  string s;
  for (i = 1; i < n; i++) cin >> s;
  cin >> s;
  for (i = 0; i < len; i++) {
    if (s[i] == 'B') {
      if (a == 0) ans++;
      a = 1;
    } else
      a = 0;
  }
  cout << ans << endl;
  return 0;
}
