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