#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans, i, j;
  char c[15][15];
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> c[i][j];
  ans = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (c[i][j] != 'W') continue;
      if ((c[i - 1][j] == 'P') || (c[i + 1][j] == 'P') ||
          (c[i][j - 1] == 'P') || (c[i][j + 1] == 'P'))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
