#include <bits/stdc++.h>
bool prime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
using namespace std;
void solve() {
  int n, m, c = 0;
  cin >> n >> m;
  char s[n + 2][m + 2], a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < m + 2; j++) {
      if ((i == 0) || (i == n + 1) || (j == 0) || (j == m + 1))
        s[i][j] = '.';
      else
        s[i][j] = a[i - 1][j - 1];
    }
  }
  for (int i = 1; i < n + 2; i++) {
    for (int j = 1; j < m + 2; j++) {
      if (s[i][j] == 'P') {
        if (s[i][j + 1] == 'W') {
          s[i][j] = '.';
          s[i][j + 1] = '.';
          c++;
        }
        if (s[i][j - 1] == 'W') {
          s[i][j] = '.';
          s[i][j - 1] = '.';
          c++;
        }
        if (s[i + 1][j] == 'W') {
          s[i][j] = '.';
          s[i + 1][j] = '.';
          c++;
        }
        if (s[i - 1][j] == 'W') {
          s[i][j] = '.';
          s[i - 1][j] = '.';
          c++;
        }
      }
    }
  }
  cout << c << endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
