#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout << setprecision(10);
  int row, column;
  char temp;
  cin >> row >> column;
  for (int i = 0; i < int(row - 1); ++i) {
    for (int j = 0; j < int(column); ++j) {
      cin >> temp;
    }
  }
  string s;
  cin >> s;
  int s1 = 0;
  for (int i = 0; i < int(column); ++i) {
    if (s[i] == 'B') {
      s1++;
      while (s[i] == 'B') i++;
    }
  }
  cout << s1;
  return 0;
}
