#include <bits/stdc++.h>
using namespace std;
long long n, m = 0, k = 0;
bool test1 = false;
long long const N = 1e5 + 7;
long long const oo = 1000000007;
long long nChoosek(long long n, long long k) {
  if (k > n) return 0;
  if (k * 2 > n) k = n - k;
  if (k == 0) return 1;
  long long result = n;
  for (long long i = 2; i <= k; ++i) {
    result *= (n - i + 1);
    result /= i;
  }
  return result;
}
vector<long long> v, v1;
vector<pair<long long, long long> > vv;
map<pair<long long, long long>, long long> my1;
map<long long, long long> my;
priority_queue<long long> q;
long long t[N];
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
long long root(long long x) {
  long long l = 0, r = 1e9 + 1;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (m * m > x)
      r = m;
    else
      l = m;
  }
  return l;
}
vector<long long> v2[N];
long long z[N];
void dfs(long long s) {
  if (z[s]) return;
  z[s] = 1;
  for (long long u = 0; u < v2[s].size(); u++) {
    dfs(v2[s][u]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long i = 0, j = 0, a = 0, b = 0, c = 0, d = 1e18, x = 0, y = 0, s = 0, r,
            l;
  string s1, s2, s3, s4, s5;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s1;
  s1 += '.';
  for (i = 0; i < m; i++) {
    if (s1[i] == 'B' && s1[i + 1] == '.') s++;
  }
  cout << s << endl;
  return 0;
}
