#include <bits/stdc++.h>
using namespace std;
int n, m, res;
bool wziety[12][12];
char tmp[12][12];
string ciag[12];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (n); i++) {
    scanf("%s", tmp[i]);
    ciag[i] = tmp[i];
  }
  for (int i = (1); i <= (n); i++)
    for (int j = (0); j <= (m - 1); j++)
      if (ciag[i][j] == 'P') {
        if (ciag[i - 1][j] == 'W' && wziety[i - 1][j] == false) {
          res++, wziety[i - 1][j] = true;
          continue;
        }
        if (ciag[i + 1][j] == 'W' && wziety[i + 1][j] == false) {
          res++, wziety[i + 1][j] = true;
          continue;
        }
        if (ciag[i][j + 1] == 'W' && wziety[i][j + 1] == false) {
          res++, wziety[i][j + 1] = true;
          continue;
        }
        if (j - 1 >= 0 && ciag[i][j - 1] == 'W' && wziety[i][j - 1] == false) {
          res++, wziety[i][j - 1] = true;
          continue;
        }
      }
  printf("%d\n", res);
  return 0;
}
