#include <bits/stdc++.h>
using namespace std;
int r, c;
char grid[11][11];
bool check(int i, int j) {
  if (i < 0 || j < 0 || i > r - 1 || j > c - 1) return false;
  return true;
}
int main(void) {
  int m, n;
  while (scanf("%d%d", &m, &n) == 2) {
    r = m, c = n;
    for (int i = 0; i < r; i++) {
      scanf("%s", grid[i]);
    }
    int cnt = 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        if (grid[i][j] == 'W') {
          if (check(i, j - 1)) {
            if (grid[i][j - 1] == 'P') {
              grid[i][j - 1] = 0;
              cnt++;
              continue;
            }
          }
          if (check(i - 1, j)) {
            if (grid[i - 1][j] == 'P') {
              grid[i - 1][j] = 0;
              cnt++;
              continue;
            }
          }
          if (check(i, j + 1)) {
            if (grid[i][j + 1] == 'P') {
              grid[i][j + 1] = 0;
              cnt++;
              continue;
            }
          }
          if (check(i + 1, j)) {
            if (grid[i + 1][j] == 'P') {
              grid[i + 1][j] = 0;
              cnt++;
              continue;
            }
          }
        }
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
