#include <bits/stdc++.h>
int map[19][19];
int hash[19][19];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i, j;
  for (i = 1; i <= n; i++) {
    getchar();
    for (j = 1; j <= m; j++) {
      char temp;
      scanf("%c", &temp);
      if (temp == 'P') map[i][j] = 2;
      if (temp == 'W') map[i][j] = 1;
      if (temp == '.') map[i][j] = 0;
    }
  }
  for (i = 1; i <= (n); i++) {
    for (j = 1; j <= (m); j++) {
      if (map[i][j] == 2) {
        hash[i][j] += (map[i - 1][j] & 1) + (map[i][j - 1] & 1) +
                      (map[i][j + 1] & 1) + (map[i + 1][j] & 1);
      }
    }
  }
  int add = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      int min = 9, r = 9;
      if (map[i][j] == 1) {
        if (map[i][j - 1] == 2) {
          if (min > hash[i][j - 1]) {
            min = hash[i][j - 1];
            r = 1;
          }
        }
        if (map[i][j + 1] == 2) {
          if (min > hash[i][j + 1]) {
            min = hash[i][j + 1];
            r = 2;
          }
        }
        if (map[i - 1][j] == 2) {
          if (min > hash[i - 1][j]) {
            min = hash[i - 1][j];
            r = 3;
          }
        }
        if (map[i + 1][j] == 2) {
          if (min > hash[i + 1][j]) {
            min = hash[i + 1][j];
            r = 4;
          }
        }
        if (r != 9) {
          add++;
          if (r == 1)
            map[i][j - 1] = 0;
          else if (r == 2)
            map[i][j + 1] = 0;
          else if (r == 3)
            map[i - 1][j] = 0;
          else
            map[i + 1][j] = 0;
        }
      }
    }
  }
  printf("%d\n", add);
}
