#include <bits/stdc++.h>
using namespace std;
int n, m, ans, cnt;
char mat[12][12];
int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
bool check(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) scanf("%s", mat[i]);
    int count = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (mat[i][j] != 'W') continue;
        int dx, dy;
        for (int k = 0; k < 4; k++) {
          dx = dir[k][0] + i, dy = j + dir[k][1];
          if (check(dx, dy) && mat[dx][dy] == 'P') {
            count++;
            break;
          }
        }
      }
    printf("%d\n", count);
  }
  return 0;
}
