#include <bits/stdc++.h>
int n, m;
char e[11][11];
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    int i, j, k;
    int t = 0;
    for (i = 0; i < n; i++) scanf("%s", e[i]);
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) {
        if (e[i][j] == 'W') {
          for (k = 0; k < 4; k++) {
            int xx, yy;
            xx = i + dir[k][0];
            yy = j + dir[k][1];
            if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue;
            if (e[xx][yy] == 'P') {
              t++;
              break;
            }
          }
        }
      }
    printf("%d\n", t);
  }
  return 0;
}
