#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char arr[100][100] = {'z'};
  vector<pair<int, int>> wolf;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      arr[i][j] = c;
      if (c == 'W') wolf.push_back(make_pair(i, j));
    }
  int pigs = 0;
  for (int i = 0; i < wolf.size(); i++) {
    if (arr[wolf[i].first - 1][wolf[i].second] == 'P' ||
        arr[wolf[i].first + 1][wolf[i].second] == 'P' ||
        arr[wolf[i].first][wolf[i].second - 1] == 'P' ||
        arr[wolf[i].first][wolf[i].second + 1] == 'P') {
      pigs++;
    }
  }
  cout << pigs << endl;
  return 0;
}
