#include <bits/stdc++.h>
using matrix2D = std::vector<std::vector<uint32_t>>;
using vector1D = std::vector<uint32_t>;
struct Wall {
  uint32_t rows;
  uint32_t cols;
  matrix2D data;
  Wall(uint32_t R, uint32_t C) : rows(R), cols(C) {
    data.resize(rows);
    for (auto& element : data) {
      element.resize(cols);
    }
    char symbol;
    for (uint32_t i = 0; i < rows; ++i) {
      for (uint32_t j = 0; j < cols; ++j) {
        std::cin >> symbol;
        switch (symbol) {
          case '.':
            (*this)(i, j) = 0;
            break;
          case 'B':
            (*this)(i, j) = 1;
            break;
        }
      }
    }
  }
  uint32_t& operator()(uint32_t i, uint32_t j) { return data[i][j]; }
  typename matrix2D::iterator begin() { return data.begin(); }
  typename matrix2D::iterator end() { return data.end(); }
  vector1D get_row(uint32_t index) { return data[index]; }
  vector1D get_column(uint32_t index) {
    vector1D column(rows);
    for (uint32_t i = 0; i < rows; ++i) {
      column[i] = (*this)(i, index);
    }
    return column;
  }
  friend std::ostream& operator<<(std::ostream& os, Wall& wall) {
    for (uint32_t i = 0; i < wall.rows; ++i) {
      for (uint32_t j = 0; j < wall.cols; ++j) {
        os << std::setw(2) << wall(i, j) << " ";
      }
      os << std::endl;
    }
    return os;
  }
};
std::ostream& operator<<(std::ostream& os, vector1D v) {
  for (auto& element : v) {
    os << std::setw(2) << element << " ";
  }
  os << std::endl;
  return os;
}
uint32_t count_wall_segments(Wall& wall) {
  auto lowest_row = wall.get_row(wall.rows - 1);
  bool left_side_empty = true;
  uint32_t counter = 0;
  for (uint32_t i = 0; i < wall.cols; ++i) {
    if (lowest_row[i] == 1 && left_side_empty) {
      ++counter;
      left_side_empty = false;
    }
    if (lowest_row[i] == 0) {
      left_side_empty = true;
    }
  }
  return counter;
}
int main() {
  uint32_t R, C;
  std::cin >> R >> C;
  Wall wall(R, C);
  std::cout << count_wall_segments(wall) << std::endl;
  return 0;
}
