#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
int main() {
  long long int N, M, res = 0;
  bool vis[100][100] = {};
  string S[10];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i][j] == 'P') {
        if (i > 0 && S[i - 1][j] == 'W') {
          if (vis[i - 1][j]) {
            continue;
          }
          S[i - 1][j] = 1;
          res++;
        } else if (i < N - 1 && S[i + 1][j] == 'W') {
          if (vis[i + 1][j]) {
            continue;
          }
          S[i + 1][j] = 1;
          res++;
        } else if (j < M - 1 && S[i][j + 1] == 'W') {
          if (vis[i][j + 1]) {
            continue;
          }
          S[i][j + 1] = 1;
          res++;
        } else if (j > 0 && S[i][j - 1] == 'W') {
          if (vis[i][j - 1]) {
            continue;
          }
          S[i][j - 1] = 1;
          res++;
        }
      }
    }
  }
  cout << res;
  return 0;
}
