#include <bits/stdc++.h>
using namespace std;
int n, m, a[15][15], ans;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string st;
    cin >> st;
    for (int j = 0; j < st.size(); ++j) {
      if (st[j] == 'P') {
        a[i][j] = 1;
      } else if (st[j] == 'W') {
        a[i][j] = 2;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == 1) {
        if (i > 0 && a[i - 1][j] == 2) {
          a[i - 1][j] = 0;
          ++ans;
          continue;
        }
        if (a[i + 1][j] == 2) {
          a[i + 1][j] = 0;
          ++ans;
          continue;
        }
        if (j > 0 && a[i][j - 1] == 2) {
          a[i][j - 1] = 0;
          ++ans;
          continue;
        }
        if (a[i][j + 1] == 2) {
          a[i][j + 1] = 0;
          ++ans;
          continue;
        }
      }
    }
  }
  cout << ans;
}
