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