#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
char grid[maxn][maxn];
int dir[][2] = {{0, 1}, {1, 0},   {0, -1}, {-1, 0},
                {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
int n, m;
void dfs(int x, int y) {
  for (int i = 0; i < 8; ++i) {
    int nx = x + dir[i][0];
    int ny = y + dir[i][1];
    if (0 <= nx && nx < n && 0 <= ny && ny < m && grid[nx][ny] == 'B') {
      grid[nx][ny] = '.';
      dfs(nx, ny);
    }
  }
}
int main() {
  while (cin >> n >> m) {
    int c = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) cin >> grid[i][j];
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        if (grid[i][j] == 'B') {
          dfs(i, j);
          c++;
        }
      }
    cout << c << endl;
  }
  return 0;
}
