#include <bits/stdc++.h>
using namespace std;
template <class T>
bool cmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int64_t inf = 1e18;
const int64_t N = 105;
int64_t n, m, answer;
char mat[N][N];
bool vis[N][N];
int64_t dx[] = {1, -1, 0, 0};
int64_t dy[] = {0, 0, -1, 1};
bool inside(int64_t i, int64_t j) {
  return i >= 1 && i <= n && j >= 1 && j <= m;
}
void go(int64_t i, int64_t j) {
  if (!inside(i, j) || mat[i][j] ^ 'B' || vis[i][j]) return;
  vis[i][j] = true;
  for (int64_t k = (0); k < (4); ++k) go(i + dx[k], j + dy[k]);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int64_t i = (1); i <= (n); ++i)
    for (int64_t j = (1); j <= (m); ++j) cin >> mat[i][j];
  for (int64_t i = (1); i <= (n); ++i)
    for (int64_t j = (1); j <= (m); ++j)
      if (mat[i][j] ^ '.' && !vis[i][j]) ++answer, go(i, j);
  cout << answer << '\n';
}
