#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  int count = 0;
  cin >> m >> n;
  int x, y;
  char a[m][n];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 'P') {
        if ((a[i + 1][j] == 'W') && ((i + 1) < m)) {
          count++;
          a[i + 1][j] = '.';
        }
        if ((a[i - 1][j] == 'W') && ((i - 1) >= 0)) {
          count++;
          a[i - 1][j] = '.';
        }
        if ((a[i][j + 1] == 'W') && ((j + 1) < n)) {
          count++;
          a[i][j + 1] = '.';
        }
        if ((a[i][j - 1] == 'W') && ((j - 1) >= 0)) {
          count++;
          a[i][j - 1] = '.';
        }
      }
    }
  }
  cout << count;
}
