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