#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T m) {
  T ret;
  if (p == 0) return 1;
  if (p & 1) {
    ret = (bigmod(b, p / 2, m) % m);
    return ((b % m) * ret * ret) % m;
  } else {
    ret = (bigmod(b, p / 2, m) % m);
    return (ret * ret) % m;
  }
}
template <class T>
inline T _sqrt(T a) {
  return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X b) {
  T res = 1;
  for (int i = 1; i <= b; i++) res *= a;
  return res;
}
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx6[] = {0, 0, 1, -1, 0, 0};
int dy6[] = {1, -1, 0, 0, 0, 0};
int dz6[] = {0, 0, 0, 0, 1, -1};
int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};
int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};
int tc = 1;
const long long int mx = 100000;
string str[10];
int n, m;
int main() {
  int i, j, ans, x, y, k;
  while (cin >> n >> m) {
    for (i = 0; i < n; i++) cin >> str[i];
    ans = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == 'W') {
          if (i - 1 >= 0 && str[i - 1][j] == 'P')
            ans++, str[i - 1][j] = '.';
          else if (i + 1 < n && str[i + 1][j] == 'P')
            ans++, str[i + 1][j] = '.';
          else if (j - 1 >= 0 && str[i][j - 1] == 'P')
            ans++, str[i][j - 1] = '.';
          else if (j + 1 < m && str[i][j + 1] == 'P')
            ans++, str[i][j + 1] = '.';
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
