#include <bits/stdc++.h>
using namespace std;
char t;
int n, m;
char a[11][11];
bool used[11][11];
int kol = 0;
int maxleng = 0;
void dfs(int x, int y, bool ch, int leng = 0) {
  if (x < 0 || y < 0 || x >= n || y >= m) return;
  if (a[x][y] == 2) return;
  if (used[x][y]) return;
  used[x][y] = true;
  if (ch) ++leng;
  if (x - 1 >= 0 && y >= 0 && x - 1 < n && y < m && a[x][y] == !a[x - 1][y])
    dfs(x - 1, y, !ch, leng);
  if (x >= 0 && y - 1 >= 0 && x < n && y - 1 < m && a[x][y] == !a[x][y - 1])
    dfs(x, y - 1, !ch, leng);
  if (x >= 0 && y + 1 >= 0 && x < n && y + 1 < m && a[x][y] == !a[x][y + 1])
    dfs(x, y + 1, !ch, leng);
  if (x + 1 >= 0 && y >= 0 && x + 1 < n && y < m && a[x][y] == !a[x + 1][y])
    dfs(x + 1, y, !ch, leng);
  maxleng = max(maxleng, leng);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> t;
      if (t == '.') a[i][j] = 2;
      if (t == 'P') a[i][j] = 0;
      if (t == 'W') a[i][j] = 1;
      used[i][j] = false;
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (!used[i][j]) maxleng = 0, dfs(i, j, 0), kol += maxleng;
  cout << kol;
  return 0;
}
