#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int dx4[] = {+1, -1, +0, +0};
int dy4[] = {+0, +0, +1, -1};
int dx8[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int dy8[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int dr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int dc[] = {-2, -2, -1, 1, 2, 2, 1, -1};
void test_case() {
  int r, c;
  cin >> r >> c;
  string s;
  for (int i = 0; i < (int)(r); ++i) cin >> s;
  int flip = 0, seg = 0;
  for (int i = 0; i < (int)(s.size()); ++i) {
    if (s[i] == 'B' and flip == 0) seg++, flip = 1;
    if (s[i] == '.') flip = 0;
  }
  cout << seg << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(15);
  cout << fixed;
  int T = 1;
  for (int tc = 1; tc <= T; ++tc) {
    test_case();
  }
  return 0;
}
