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