#include <bits/stdc++.h>
char a[12][12] = {0};
int srch(int i, int j) {
  int c = 0;
  if (a[i + -1][j + 0] == 'W') c++;
  if (a[i + 0][j + 1] == 'W') c++;
  if (a[i + 1][j + 0] == 'W') c++;
  if (a[i + 0][j + -1] == 'W') c++;
  return c;
}
void srch2(int i, int j) {
  if (a[i + -1][j + 0] == 'W') a[i + -1][j + 0] = '.';
  if (a[i + 0][j + 1] == 'W') a[i + 0][j + 1] = '.';
  if (a[i + 1][j + 0] == 'W') a[i + 1][j + 0] = '.';
  if (a[i + 0][j + -1] == 'W') a[i + 0][j + -1] = '.';
}
int main() {
  int n, m;
  int i, j;
  int s = 0;
  bool f;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", &a[i][1]);
  do {
    f = false;
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++)
        if (a[i][j] == 'P')
          if (srch(i, j) == 1) {
            srch2(i, j);
            a[i][j] = '.';
            f = true;
            s++;
          }
  } while (f == true);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == 'P')
        if (srch(i, j) > 0) {
          a[i][j] = '.';
          s++;
          if (a[i + -1][j + 0] == 'W') {
            a[i + -1][j + 0] = '.';
            continue;
          };
          if (a[i + 0][j + 1] == 'W') {
            a[i + 0][j + 1] = '.';
            continue;
          };
          if (a[i + 1][j + 0] == 'W') {
            a[i + 1][j + 0] = '.';
            continue;
          };
          if (a[i + 0][j + -1] == 'W') {
            a[i + 0][j + -1] = '.';
            continue;
          };
        }
  printf("%d", s);
  return 0;
}
