#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, x, flag = 0, flag1 = 0, t, p, l, k, y, ans = 0, m, m1, x1,
                      y1, x2, y2, b[100005], q, r, j;
  char a[1005][1005];
  cin >> x >> y;
  for (i = 1; i <= x; i++) {
    for (j = 1; j <= y; j++) cin >> a[i][j];
  }
  for (i = 1; i <= x; i++) {
    for (j = 1; j <= y; j++) {
      if (a[i][j] == 'W') {
        if (a[i][j - 1] == 'P' || a[i][j + 1] == 'P' || a[i - 1][j] == 'P' ||
            a[i + 1][j] == 'P')
          flag++;
      }
    }
  }
  cout << flag << endl;
  return 0;
}
