#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char** grid = new char*[n];
  vector<pair<int, int>> pigs;
  for (int i = 0; i < n; i++) {
    grid[i] = new char[m];
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == 'P') {
        pair<int, int> temp;
        temp.first = i;
        temp.second = j;
        pigs.push_back(temp);
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < pigs.size(); i++) {
    int x = pigs[i].first, y = pigs[i].second;
    if (x != n - 1 && grid[x + 1][y] == 'W') {
      grid[x + 1][y] = '*';
      sum++;
    } else if (x != 0 && grid[x - 1][y] == 'W') {
      grid[x - 1][y] = '*';
      sum++;
    } else if (y != m - 1 && grid[x][y + 1] == 'W') {
      grid[x][y + 1] = '*';
      sum++;
    } else if (y != 0 && grid[x][y - 1] == 'W') {
      grid[x][y - 1] = '*';
      sum++;
    }
  }
  cout << sum << endl;
}
