#include <bits/stdc++.h>
using namespace std;
const char nxtl = (char)'\n';
const int maxn = (int)2e5 + 5;
const int INF_INT = (int)1e9 + 99;
const long long INF_BIG = (long long)1e18 + 99;
const int MOD = (int)1e9 + 7;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool used[150][150];
char a[150][150];
int n, m;
bool check(int x, int y) {
  return (x > 0 && x <= n && y > 0 && y <= m && a[x][y] == 'B');
}
void dfs(int x, int y) {
  used[x][y] = true;
  for (int i = 0; i < 4; ++i) {
    if (!used[x + dx[i]][y + dy[i]] && check(x + dx[i], y + dy[i]))
      dfs(x + dx[i], dy[i] + y);
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == 'B')
        if (!used[i][j]) dfs(i, j), cnt++;
  cout << cnt;
  return 0;
}
