#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535;
long long powi(long long base, int p) {
  long long res = 1;
  while (p--) res *= base;
  return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool is_vowel(char c) {
  c = tolower(c);
  return c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u' || c == 'y';
}
char field[101][101];
int res = 0;
int r, c;
void explore(int i, int j) {
  if (field[i][j] != 'B') return;
  field[i][j] = '.';
  if (i > 0) explore(i - 1, j);
  if (i + 1 < r) explore(i + 1, j);
  if (j > 0) explore(i, j - 1);
  if (j + 1 < c) explore(i, j + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) cin >> field[i][j];
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (field[i][j] == 'B') {
        res++;
        explore(i, j);
      }
    }
  }
  cout << res;
  return 0;
}
