#include <bits/stdc++.h>
using namespace std;
char o[11][11];
int main() {
  int n, m, c = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> o[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (o[i][j] == 'P') {
        if (o[i - 1][j] == 'W') {
          c++;
          o[i - 1][j] = '.';
        } else if (o[i + 1][j] == 'W') {
          c++;
          o[i + 1][j] = '.';
        } else if (o[i][j + 1] == 'W') {
          c++;
          o[i][j + 1] = '.';
        } else if (o[i][j - 1] == 'W') {
          c++;
          o[i][j - 1] = '.';
        }
      }
    }
  cout << c << endl;
  return 0;
}
