#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  int a[10][10];
  for (int i = 0; i < x; i++)
    for (int j = 0; j < y; j++) {
      char z;
      cin >> z;
      if (z == 'W')
        a[i][j] = -1;
      else if (z == '.')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  int count = 0;
  for (int i = 0; i < x; i++)
    for (int j = 0; j < y; j++) {
      if (a[i][j] == 1) {
        int f = 1;
        if (i != 0 && a[i - 1][j] == -1) {
          a[i - 1][j] = 0;
          f = 0;
        } else if (j != 0 && a[i][j - 1] == -1) {
          a[i][j - 1] = 0;
          f = 0;
        } else if (i != x - 1 && a[i + 1][j] == -1) {
          a[i + 1][j] = 0;
          f = 0;
        } else if (j != y - 1 && a[i][j + 1] == -1) {
          a[i][j + 1] = 0;
          f = 0;
        }
        if (!f) count++;
      }
    }
  cout << count;
  return 0;
}
