#include <bits/stdc++.h>
using namespace std;
bool sortcoll(vector<long long int> &v1, vector<long long int> &v2) {
  return v1[0] < v2[0];
}
bool isAdjacent(vector<vector<char> > &arr, int r, int c) {
  if (r != 0 && arr[r - 1][c] == 'P')
    return true;
  else if (r != arr.size() - 1 && arr[r + 1][c] == 'P')
    return true;
  else if (c != 0 && arr[r][c - 1] == 'P')
    return true;
  else if (c != arr[0].size() - 1 && arr[r][c + 1] == 'P')
    return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<vector<char> > arr(n, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  long long int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 'W') {
        if (isAdjacent(arr, i, j)) count++;
      }
    }
  }
  cout << count;
  return 0;
}
