#include <bits/stdc++.h>
using namespace std;
bool comp(int& a, int& b) { return a > b; }
int main() {
  int r, c;
  cin >> r >> c;
  vector<string> wall;
  for (int i = 0; i < r; ++i) {
    string row;
    cin >> row;
    wall.push_back(row);
  }
  int ans = 0;
  r--;
  for (int i = 0; i < c; ++i) {
    if (wall[r][i] == 'B') {
      ans++;
      while (i < c && wall[r][i] == 'B') {
        i++;
      }
    }
  }
  cout << ans;
  return 0;
}
