#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 998244353;
int n, m;
char s[100][100], vis[100][100];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'P') {
        for (int k = 0; k < 4; k++) {
          if (s[i + dx[k]][j + dy[k]] == 'W' &&
              vis[i + dx[k]][j + dy[k]] == 0) {
            ans++;
            vis[i + dx[k]][j + dy[k]] = 1;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
}
