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