#include <bits/stdc++.h>
using namespace std;
char m[105][105];
void ff(int i, int j) {
  if (m[i][j] == 'B') {
    m[i][j] = '.';
    ff(i + 1, j);
    ff(i - 1, j);
    ff(i, j + 1);
    ff(i, j - 1);
  }
}
int main() {
  int b, k;
  cin >> b >> k;
  for (int i = 1; i <= b; i++) {
    for (int j = 1; j <= k; j++) {
      cin >> m[i][j];
    }
  }
  for (int i = 0; i <= b + 1; i++) {
    for (int j = 0; j <= k + 1; j++) {
      if (i == 0 || i == b + 1 || j == 0 || j == k + 1) m[i][j] = '.';
    }
  }
  int jum = 0;
  for (int i = 1; i <= b; i++) {
    for (int j = 1; j <= k; j++) {
      if (m[i][j] == 'B') {
        jum++;
        ff(i, j);
      }
    }
  }
  cout << jum << endl;
  return 0;
}
