#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
bool vis[102][102];
char arr[102][102];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int i, int j) { return (i >= 0 && j >= 0 && i < n && j < m); }
void dfs(int i, int j) {
  if (!valid(i, j)) return;
  if (vis[i][j]) return;
  vis[i][j] = true;
  for (int k = 0; k < 4; ++k)
    if (arr[i + dx[k]][j + dy[k]] == 'B' && !vis[i + dx[k]][j + dy[k]])
      dfs(i + dx[k], j + dy[k]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (arr[i][j] == 'B' && !vis[i][j]) ans++, dfs(i, j);
  cout << ans << endl;
  return 0;
}
