#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
char magic[101][101];
vector<ll> primes;
bool fk[1000001];
int main() {
  ios_base::sync_with_stdio(false);
  string str;
  ll a, c, d, e, f, x, y, t, A = 0, B = 0, L, j, i, l, r, m, n, C = 0, ans = 0,
                             sum = 0, sum1 = 0;
  vector<ll> v, v1;
  queue<ll> qu;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> magic[i];
  }
  if (magic[n - 1][0] == 'B') A++;
  for (j = 1; j < m; j++) {
    if (magic[n - 1][j] == 'B' && magic[n - 1][j - 1] == '.') A++;
  }
  cout << A << endl;
}
