#include <bits/stdc++.h>
int main() {
  static char cc[10][10 + 1];
  int n, m, i, j, cnt;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", cc[i]);
  cnt = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (cc[i][j] == 'W')
        if (cc[i][j - 1] == 'P')
          cnt++, cc[i][j - 1] = '.';
        else if (cc[i - 1][j] == 'P')
          cnt++, cc[i - 1][j] = '.';
        else if (cc[i][j + 1] == 'P')
          cnt++, cc[i][j + 1] = '.';
        else if (cc[i + 1][j] == 'P')
          cnt++, cc[i + 1][j] = '.';
  printf("%d\n", cnt);
  return 0;
}
