#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
struct killers {
  char *game;
  int *counter;
};
int main() {
  setlocale(LC_ALL, "Russian");
  int n, m, i, j, count = 0;
  cin >> n;
  cin >> m;
  killers *massiv = new killers[n];
  for (i = 0; i < n; i++) {
    massiv[i].game = (char *)malloc(m * sizeof(int));
    massiv[i].counter = (int *)malloc(m * sizeof(int));
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> massiv[i].game[j];
      massiv[i].counter[j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (massiv[i].game[j] == 'W') {
        if ((i != 0 && massiv[i - 1].game[j] == 'P') ||
            (j != 0 && massiv[i].game[j - 1] == 'P') ||
            (j != m - 1 && massiv[i].game[j + 1] == 'P') ||
            (i != n - 1 && massiv[i + 1].game[j] == 'P')) {
          if (massiv[i].counter[j] == 0) {
            massiv[i].counter[j]++;
            count++;
          }
        }
      }
    }
  }
  cout << count;
  return 0;
}
