#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
mt19937 ggen;
int r, c;
char w[110][110];
int u[110][110];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
void dfs(int x, int y) {
  u[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || nx >= r || ny < 0 || ny >= c || u[nx][ny] || w[nx][ny] == '.')
      continue;
    dfs(nx, ny);
  }
}
void solve() {
  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) cin >> w[i][j];
  int ans = 0;
  for (int i = 0; i < c; i++)
    if (!u[r - 1][i] && w[r - 1][i] == 'B') {
      dfs(r - 1, i);
      ans++;
    }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  ggen = mt19937(13);
  solve();
  return 0;
}
