#include <bits/stdc++.h>
using namespace std;
int n, m;
char M[15][15];
pair<int, int> dir[] = {make_pair(0, 1), make_pair(0, -1), make_pair(1, 0),
                        make_pair(-1, 0)};
bool isSafe(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < m); }
int getPos(vector<pair<int, int> > &v) {
  int q = 1e9;
  pair<int, int> pos(-1, -1);
  for (int k = 0; k < (int)int((v).size()); k++) {
    int i = v[k].first;
    int j = v[k].second;
    int cont = 0;
    if (M[i][j] == 'P') {
      for (int l = 0; l < (int)4; l++) {
        int x = dir[l].first + i;
        int y = dir[l].second + j;
        if (isSafe(x, y) && M[x][y] == 'W') cont++;
      }
    }
    if (cont == 0)
      M[i][j] == '.';
    else if (cont < q) {
      q = cont;
      pos = make_pair(i, j);
    }
  }
  if (pos != make_pair(-1, -1)) {
    M[pos.first][pos.second] = '.';
    for (int l = 0; l < (int)4; l++) {
      int x = dir[l].first + pos.first;
      int y = dir[l].second + pos.second;
      if (isSafe(x, y) && M[x][y] == 'W') {
        M[x][y] = '.';
        break;
      }
    }
  }
  return q;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<pair<int, int> > v;
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)m; j++) {
      cin >> M[i][j];
      if (M[i][j] == 'P') v.push_back(make_pair(i, j));
    }
  int ans = 0;
  while (getPos(v) != 1e9) {
    ans++;
  }
  cout << ans << "\n";
  return 0;
}
