#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, h, i, j, t, m, l, r, q;
  long long p = 0, k, w, z, x, y, d;
  string s = "", st = "", s1 = "", s2 = "";
  q = 1;
  char c;
  for (l = 0; l < q; l++) {
    std::cin >> n >> m;
    char a[n][m];
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) cin >> a[i][j];
    }
    p = 0;
    if (a[n - 1][0] == 'B') p = 1;
    for (j = 0; j < m; j++) {
      if (j != m - 1 && a[n - 1][j] != a[n - 1][j + 1] && a[n - 1][j] == '.')
        p++;
    }
    std::cout << p << std::endl;
  }
  return 0;
}
