#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
long long n, m;
int main() {
  int n, m, cnt = 0;
  cin >> n >> m;
  g.assign(n, vector<int>(m, 0));
  char ch;
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (m); ++(j)) {
      cin >> ch;
      if (ch == '.') g[i][j] = 0;
      if (ch == 'P') g[i][j] = 1;
      if (ch == 'W') g[i][j] = 2;
    }
  }
  set<pair<int, pair<int, int> > > q;
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (m); ++(j)) {
      cnt = 0;
      if (g[i][j] == 2) {
        if (i > 0 && g[i - 1][j] == 1) {
          cnt++;
        }
        if (j > 0 && g[i][j - 1] == 1) {
          cnt++;
        }
        if (i < n - 1 && g[i + 1][j] == 1) {
          cnt++;
        }
        if (j < m - 1 && g[i][j + 1] == 1) {
          cnt++;
        }
        q.insert(make_pair(cnt, make_pair(i, j)));
      }
    }
  }
  cnt = 0;
  while (!q.empty()) {
    int i = q.begin()->second.first;
    int j = q.begin()->second.second;
    q.erase(q.begin());
    if (i > 0 && g[i - 1][j] == 1) {
      cnt++;
      g[i - 1][j] = 0;
      continue;
    }
    if (j > 0 && g[i][j - 1] == 1) {
      cnt++;
      g[i][j - 1] = 0;
      continue;
    }
    if (i < n - 1 && g[i + 1][j] == 1) {
      cnt++;
      g[i + 1][j] = 0;
      continue;
    }
    if (j < m - 1 && g[i][j + 1] == 1) {
      cnt++;
      g[i][j + 1] = 0;
      continue;
    }
  }
  cout << cnt << endl;
  return 0;
}
