#include <bits/stdc++.h>
using namespace std;
char m[105][105];
bool vis[105][105];
int xPos[4] = {1, 0, -1, 0};
int yPos[4] = {0, 1, 0, -1};
int a, b;
void dfs(int x, int y) {
  if (x >= a || x < 0 || y >= b || y < 0) return;
  if (m[x][y] == 'B' && vis[x][y] == false) {
    vis[x][y] = true;
    for (int i = 0; i < 4; i++) {
      dfs(x + xPos[i], y + yPos[i]);
    }
  }
}
int main() {
  int ans = 0;
  while (cin >> a >> b) {
    ans = 0;
    memset(vis, false, sizeof(vis));
    for (int i = 0; i < a; i++)
      for (int j = 0; j < b; j++) cin >> m[i][j];
    for (int i = 0; i < a; i++)
      for (int j = 0; j < b; j++) {
        if (m[i][j] == 'B' && vis[i][j] == false) {
          dfs(i, j);
          ans++;
        }
      }
    cout << ans << endl;
  }
  return 0;
}
