#include <bits/stdc++.h>
int m, n;
int count;
char map[11][11];
int main() {
  int i, j;
  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') {
          if (j - 1 >= 1 && map[i][j - 1] == 'P') {
            map[i][j] = '.';
            map[i][j - 1] = '.';
            count++;
            continue;
          }
          if (i - 1 >= 1 && map[i - 1][j] == 'P') {
            map[i][j] = '.';
            map[i - 1][j] = '.';
            count++;
            continue;
          }
          if (j + 1 <= n && map[i][j + 1] == 'P') {
            map[i][j] = '.';
            map[i][j + 1] = '.';
            count++;
            continue;
          }
          if (i + 1 <= m && map[i + 1][j] == 'P') {
            map[i][j] = '.';
            map[i + 1][j] = '.';
            count++;
            continue;
          }
        }
      }
    }
    printf("%d\n", count);
  }
  return 0;
}
