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