#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, m = 0, n, t, x, z, y, p = 0, ans = 0, mn = 10000000009,
                     mx = 0;
  cin >> n >> m;
  char s[50][50];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> s[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (s[i][j] == 'W') {
        if (s[i - 1][j] == 'P') {
          s[i - 1][j] = '*';
          ans++;
          continue;
        } else if (s[i + 1][j] == 'P') {
          s[i + 1][j] = '*';
          ans++;
          continue;
        } else if (s[i][j - 1] == 'P') {
          s[i][j - 1] = '*';
          ans++;
          continue;
        } else if (s[i][j + 1] == 'P') {
          s[i][j + 1] = '*';
          ans++;
          continue;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
