#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char arr[12][12];
bool valid(int i, int j) { return (!(i < 0 || j < 0 || i >= n || j >= m)); }
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cin >> arr[i][j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] == 'P') {
        if (valid(i - 1, j)) {
          if (arr[i - 1][j] == 'W') {
            ans++;
            arr[i - 1][j] = '.';
            continue;
          }
        }
        if (valid(i, j - 1)) {
          if (arr[i][j - 1] == 'W') {
            ans++;
            arr[i][j - 1] = '.';
            continue;
          }
        }
        if (valid(i + 1, j)) {
          if (arr[i + 1][j] == 'W') {
            ans++;
            arr[i + 1][j] = '.';
            continue;
          }
        }
        if (valid(i, j + 1)) {
          if (arr[i][j + 1] == 'W') {
            ans++;
            arr[i][j + 1] = '.';
            continue;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
