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