#include <bits/stdc++.h>
using namespace std;
int main() {
  int R, C;
  vector<int> counters;
  int counter = 1;
  int B = 0;
  vector<char> lastrow;
  char wall[100][100];
  cin >> R >> C;
  for (int i = 0; i < R; i++) {
    for (int k = 0; k < C; k++) {
      cin >> wall[i][k];
    }
  }
  for (int i = 0; i < C; i++) {
    if (wall[R - 1][i] == 'B') B++;
  }
  for (int i = 0; i < C; i++) {
    lastrow.push_back(wall[R - 1][i]);
  }
  for (int i = 0; i < lastrow.size() - 1; i++) {
    if (lastrow[i] == 'B' && lastrow[i + 1] == 'B')
      counter++;
    else {
      counters.push_back(counter);
      counter = 1;
    }
  }
  counters.push_back(counter);
  int solution;
  int consegments = 0;
  int sum = 0;
  for (int i = 0; i < counters.size(); i++) {
    if (counters[i] != 1) {
      consegments++;
      sum += counters[i];
    }
  }
  int missegements = B - sum;
  cout << consegments + missegements;
  return 0;
}
