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