#include <bits/stdc++.h>
using namespace std;
struct cmp {
  bool operator()(const string &a, const string &b) { return a + b < b + a; }
};
long long POW(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res % 1000000007;
}
bool prime[(long long)1e7]{};
void erat() {
  for (int i = 2; i < 1000001; i++) {
    long long a = i;
    if (!prime[i]) {
      while (a < 1000001) {
        a += i;
        prime[a] = true;
      }
    }
  }
}
long long n, m;
char qwe[1001][1001]{};
bool boo[1001][1001]{};
void dfs(long long i, long long j) {
  if (i - 1 >= 0) {
    if (qwe[i - 1][j] == 'B' && !boo[i - 1][j]) {
      boo[i - 1][j] = true;
      dfs(i - 1, j);
    }
  }
  if (i + 1 < n) {
    if (qwe[i + 1][j] == 'B' && !boo[i + 1][j]) {
      boo[i + 1][j] = true;
      dfs(i + 1, j);
    }
  }
  if (j - 1 >= 0) {
    if (qwe[i][j - 1] == 'B' && !boo[i][j - 1]) {
      boo[i][j - 1] = true;
      dfs(i, j - 1);
    }
  }
  if (j + 1 < m) {
    if (qwe[i][j + 1] == 'B' && !boo[i][j + 1]) {
      boo[i][j + 1] = true;
      dfs(i, j + 1);
    }
  }
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  long long count = 0;
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> qwe[i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (!boo[i][j])
        if (qwe[i][j] == 'B') {
          dfs(i, j);
          count++;
        }
    }
  cout << count;
  return 0;
}
