#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << "\n";
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  char arr[n + 2][m + 2];
  for (long long int(i) = 1; (i) <= (n); (i)++) {
    for (long long int(j) = 1; (j) <= (m); (j)++) {
      cin >> arr[i][j];
    }
  }
  long long int ct = 0;
  for (long long int(i) = 1; (i) <= (n); (i)++) {
    for (long long int(j) = 1; (j) <= (m); (j)++) {
      if (arr[i][j] == 'W') {
        if (arr[i + 1][j] == 'P' || arr[i - 1][j] == 'P' ||
            arr[i][j + 1] == 'P' || arr[i][j - 1] == 'P')
          ct++;
      }
    }
  }
  cout << ct << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
