#include <bits/stdc++.h>
int n, m, a[10][10];
using namespace std;
bool check_for_neighbors(int i, int j) {
  int b = 0;
  if (i > 0) {
    b += (a[i - 1][j] == 1);
  }
  if (j < m - 1) {
    b += (a[i][j + 1] == 1);
  }
  if (j > 0) {
    b += (a[i][j - 1] == 1);
  }
  if (i < n - 1) {
    b += (a[i + 1][j] == 1);
  }
  return b;
}
int main() {
  string s;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == 'P') {
        a[i][j] = 1;
      } else if (s[j] == 'W') {
        a[i][j] = 2;
      }
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 2) {
        if (check_for_neighbors(i, j)) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}
