#include <bits/stdc++.h>
using namespace std;
FILE* _fin = stdin;
FILE* _fout = stdout;
int _min(int a, int b) { return a <= b ? a : b; }
int _min(long long a, long long b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(long long a, long long b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(long long* data, int n) { memset(data, 0, sizeof(long long) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() {
  char var;
  fscanf(_fin, "%c", &var);
  return var;
}
int readi() {
  int var;
  fscanf(_fin, "%d", &var);
  return var;
}
double readlf() {
  double var;
  fscanf(_fin, "%lf", &var);
  return var;
}
long long readll() {
  long long var;
  fscanf(_fin, "%lld", &var);
  return var;
}
void repread(int* data, int n) {
  for (int i = 0; i < n; ++i) data[i] = readi();
}
void repread(long long* data, int n) {
  for (int i = 0; i < n; ++i) data[i] = readll();
}
int reads(char* str, int maxsize) {
  for (;;) {
    if (fgets(str, maxsize, _fin) == NULL) break;
    if (str[0] != '\n' && str[0] != '\r') break;
  }
  int slen = strlen(str);
  if (slen == 0) return 0;
  if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
  return slen;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return (a / g) * b;
}
void reverse(char* data, int n) {
  int k = n >> 1;
  for (int i = 0; i < k; ++i) {
    char tmp = data[i];
    data[i] = data[n - i - 1];
    data[n - i - 1] = tmp;
  }
}
void reverse(int* data, int n) {
  int k = n >> 1;
  for (int i = 0; i < k; ++i) {
    int tmp = data[i];
    data[i] = data[n - i - 1];
    data[n - i - 1] = tmp;
  }
}
struct Veci {
  int* data;
  int size;
  int n;
};
void init(Veci* t, int size) {
  t->data = (int*)malloc(sizeof(int) * size);
  t->size = size;
  t->n = 0;
}
void resize(Veci* t) {
  int ns = t->size * 1.2f;
  t->data = (int*)realloc(t->data, sizeof(int) * ns);
  t->size = ns;
}
void add(Veci* t, int val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Veci* t) { free(t->data); }
struct Vecll {
  long long* data;
  int size;
  int n;
};
void init(Vecll* t, int size) {
  t->data = (long long*)malloc(sizeof(long long) * size);
  t->size = size;
  t->n = 0;
}
void resize(Vecll* t) {
  int ns = t->size * 1.2f;
  t->data = (long long*)realloc(t->data, sizeof(long long) * ns);
  t->size = ns;
}
void add(Vecll* t, long long val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Vecll* t) { free(t->data); }
struct Vecs {
  char** data;
  int size;
  int n;
};
void init(Vecs* t, int size) {
  t->data = (char**)malloc(sizeof(char*) * size);
  t->size = size;
  t->n = 0;
}
void resize(Vecs* t) {
  int ns = t->size * 1.2f;
  t->data = (char**)realloc(t->data, sizeof(char*) * ns);
  t->size = ns;
}
void add(Vecs* t, char* val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Vecs* t) { free(t->data); }
int ispali(int* a, int* b, int n) {
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[n - i - 1]) {
      return 0;
    }
  }
  return 1;
}
int ispalc(char* a, char* b, int n) {
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[n - i - 1]) {
      return 0;
    }
  }
  return 1;
}
struct Pairi {
  int x, y;
};
int cmp_Pairi(const void* _a, const void* _b) {
  Pairi* a = (Pairi*)_a;
  Pairi* b = (Pairi*)_b;
  if (a->x < b->x)
    return -1;
  else {
    if (a->x == b->x) {
      if (a->y == b->y) return 0;
      if (a->y < b->y)
        return -1;
      else
        return 1;
    } else {
      return 1;
    }
  }
}
void sort_Pairi(Pairi* d, int n) { qsort(d, n, sizeof(Pairi), cmp_Pairi); }
int cmp_Str(const void* _a, const void* _b) {
  char* a = *((char**)_a);
  char* b = *((char**)_b);
  return strcmp(a, b);
}
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }
long long expmod(long long x, long long n, long long m) {
  long long ans = 1;
  for (; n;) {
    if (n & 1) ans = (ans * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return ans;
}
long long combmod(long long n, long long k, long long m) {
  long long ret = 1;
  long long div = 1;
  for (long long i = 0; i < k; ++i) {
    ret = (ret * (n - i) % m) % m;
    div = (div * (i + 1)) % m;
  }
  div = expmod(div, m - 2, m) % m;
  return (ret * div) % m;
}
int next_perm(int* data, int n) {
  int rootidx = -1;
  for (int i = n - 2; i >= 0; --i) {
    if (data[i] < data[i + 1]) {
      rootidx = i;
      break;
    }
  }
  if (rootidx == -1) return 0;
  int ceilingidx = rootidx + 1;
  for (int i = rootidx + 2; i < n; ++i) {
    if (data[i] > data[rootidx] && data[i] < data[ceilingidx]) {
      ceilingidx = i;
    }
  }
  {
    int t = data[rootidx];
    data[rootidx] = data[ceilingidx];
    data[ceilingidx] = t;
  };
  std::sort(&data[rootidx + 1], &data[rootidx + 1] + n - rootidx - 1);
  return 1;
}
int count_digits(long long a) {
  int k = 0;
  for (;;) {
    if (a == 0) break;
    k++;
    a /= 10;
  }
  return k;
}
int bs_exists(int* data, int n, int val) {
  int left = 0;
  int right = n - 1;
  for (; left < right;) {
    int mid = (left + right + 1) >> 1;
    if (data[mid] <= val)
      left = mid;
    else
      right = mid - 1;
  }
  return right;
}
void dfs(char s[11][11], int n, int m, int eaten, int pigsleft,
         int* besteaten) {
  if (pigsleft <= 0) return;
  if (eaten + pigsleft <= *besteaten) return;
  if (eaten > *besteaten) {
    *besteaten = eaten;
  }
  char tmp[11][11];
  for (int i = 0; i < n; ++i) memcpy(tmp[i], s[i], m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%c", tmp[i][j]);
    }
    printf("\n");
  }
  getchar();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (tmp[i][j] == 'W') {
        if (i != 0 && tmp[i - 1][j] == 'P') {
          tmp[i - 1][j] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (i != n - 1 && tmp[i + 1][j] == 'P') {
          tmp[i + 1][j] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (j != 0 && tmp[i][j - 1] == 'P') {
          tmp[i][j - 1] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (j != m - 1 && s[i][j + 1] == 'P') {
          tmp[i][j + 1] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
      }
    }
  }
}
int main() {
  {
    _fin = fopen("input.txt", "r");
    if (_fin == NULL) _fin = stdin;
  };
  int n = readi();
  int m = readi();
  static char s[11][11];
  for (int i = 0; i < n; ++i) reads(s[i], 11);
  int nwolfcaneat = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'W') {
        int pigcount = 0;
        if (i != 0 && s[i - 1][j] == 'P') pigcount++;
        if (i != n - 1 && s[i + 1][j] == 'P') pigcount++;
        if (j != 0 && s[i][j - 1] == 'P') pigcount++;
        if (j != m - 1 && s[i][j + 1] == 'P') pigcount++;
        if (pigcount != 0) nwolfcaneat++;
      }
    }
  }
  fprintf(_fout, "%d\n", nwolfcaneat);
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size n × m. Each cell in this grid was either empty, containing one little pig, or containing one wolf.

A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs.

They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf.

What is the maximum number of little pigs that may be eaten by the wolves?

Input

The first line contains integers n and m (1 ≤ n, m ≤ 10) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow n lines containing m characters each — that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf. 

It is guaranteed that there will be at most one wolf adjacent to any little pig.

Output

Print a single number — the maximal number of little pigs that may be eaten by the wolves.

Examples

Input

2 3
PPW
W.P


Output

2


Input

3 3
P.W
.P.
W.P


Output

0

Note

In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows. 

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
FILE* _fin = stdin;
FILE* _fout = stdout;
int _min(int a, int b) { return a <= b ? a : b; }
int _min(long long a, long long b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(long long a, long long b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(long long* data, int n) { memset(data, 0, sizeof(long long) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() {
  char var;
  fscanf(_fin, "%c", &var);
  return var;
}
int readi() {
  int var;
  fscanf(_fin, "%d", &var);
  return var;
}
double readlf() {
  double var;
  fscanf(_fin, "%lf", &var);
  return var;
}
long long readll() {
  long long var;
  fscanf(_fin, "%lld", &var);
  return var;
}
void repread(int* data, int n) {
  for (int i = 0; i < n; ++i) data[i] = readi();
}
void repread(long long* data, int n) {
  for (int i = 0; i < n; ++i) data[i] = readll();
}
int reads(char* str, int maxsize) {
  for (;;) {
    if (fgets(str, maxsize, _fin) == NULL) break;
    if (str[0] != '\n' && str[0] != '\r') break;
  }
  int slen = strlen(str);
  if (slen == 0) return 0;
  if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
  return slen;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return (a / g) * b;
}
void reverse(char* data, int n) {
  int k = n >> 1;
  for (int i = 0; i < k; ++i) {
    char tmp = data[i];
    data[i] = data[n - i - 1];
    data[n - i - 1] = tmp;
  }
}
void reverse(int* data, int n) {
  int k = n >> 1;
  for (int i = 0; i < k; ++i) {
    int tmp = data[i];
    data[i] = data[n - i - 1];
    data[n - i - 1] = tmp;
  }
}
struct Veci {
  int* data;
  int size;
  int n;
};
void init(Veci* t, int size) {
  t->data = (int*)malloc(sizeof(int) * size);
  t->size = size;
  t->n = 0;
}
void resize(Veci* t) {
  int ns = t->size * 1.2f;
  t->data = (int*)realloc(t->data, sizeof(int) * ns);
  t->size = ns;
}
void add(Veci* t, int val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Veci* t) { free(t->data); }
struct Vecll {
  long long* data;
  int size;
  int n;
};
void init(Vecll* t, int size) {
  t->data = (long long*)malloc(sizeof(long long) * size);
  t->size = size;
  t->n = 0;
}
void resize(Vecll* t) {
  int ns = t->size * 1.2f;
  t->data = (long long*)realloc(t->data, sizeof(long long) * ns);
  t->size = ns;
}
void add(Vecll* t, long long val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Vecll* t) { free(t->data); }
struct Vecs {
  char** data;
  int size;
  int n;
};
void init(Vecs* t, int size) {
  t->data = (char**)malloc(sizeof(char*) * size);
  t->size = size;
  t->n = 0;
}
void resize(Vecs* t) {
  int ns = t->size * 1.2f;
  t->data = (char**)realloc(t->data, sizeof(char*) * ns);
  t->size = ns;
}
void add(Vecs* t, char* val) {
  if (t->n >= t->size) resize(t);
  int k = t->n;
  t->data[k] = val;
  t->n = k + 1;
}
void free(Vecs* t) { free(t->data); }
int ispali(int* a, int* b, int n) {
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[n - i - 1]) {
      return 0;
    }
  }
  return 1;
}
int ispalc(char* a, char* b, int n) {
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[n - i - 1]) {
      return 0;
    }
  }
  return 1;
}
struct Pairi {
  int x, y;
};
int cmp_Pairi(const void* _a, const void* _b) {
  Pairi* a = (Pairi*)_a;
  Pairi* b = (Pairi*)_b;
  if (a->x < b->x)
    return -1;
  else {
    if (a->x == b->x) {
      if (a->y == b->y) return 0;
      if (a->y < b->y)
        return -1;
      else
        return 1;
    } else {
      return 1;
    }
  }
}
void sort_Pairi(Pairi* d, int n) { qsort(d, n, sizeof(Pairi), cmp_Pairi); }
int cmp_Str(const void* _a, const void* _b) {
  char* a = *((char**)_a);
  char* b = *((char**)_b);
  return strcmp(a, b);
}
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }
long long expmod(long long x, long long n, long long m) {
  long long ans = 1;
  for (; n;) {
    if (n & 1) ans = (ans * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return ans;
}
long long combmod(long long n, long long k, long long m) {
  long long ret = 1;
  long long div = 1;
  for (long long i = 0; i < k; ++i) {
    ret = (ret * (n - i) % m) % m;
    div = (div * (i + 1)) % m;
  }
  div = expmod(div, m - 2, m) % m;
  return (ret * div) % m;
}
int next_perm(int* data, int n) {
  int rootidx = -1;
  for (int i = n - 2; i >= 0; --i) {
    if (data[i] < data[i + 1]) {
      rootidx = i;
      break;
    }
  }
  if (rootidx == -1) return 0;
  int ceilingidx = rootidx + 1;
  for (int i = rootidx + 2; i < n; ++i) {
    if (data[i] > data[rootidx] && data[i] < data[ceilingidx]) {
      ceilingidx = i;
    }
  }
  {
    int t = data[rootidx];
    data[rootidx] = data[ceilingidx];
    data[ceilingidx] = t;
  };
  std::sort(&data[rootidx + 1], &data[rootidx + 1] + n - rootidx - 1);
  return 1;
}
int count_digits(long long a) {
  int k = 0;
  for (;;) {
    if (a == 0) break;
    k++;
    a /= 10;
  }
  return k;
}
int bs_exists(int* data, int n, int val) {
  int left = 0;
  int right = n - 1;
  for (; left < right;) {
    int mid = (left + right + 1) >> 1;
    if (data[mid] <= val)
      left = mid;
    else
      right = mid - 1;
  }
  return right;
}
void dfs(char s[11][11], int n, int m, int eaten, int pigsleft,
         int* besteaten) {
  if (pigsleft <= 0) return;
  if (eaten + pigsleft <= *besteaten) return;
  if (eaten > *besteaten) {
    *besteaten = eaten;
  }
  char tmp[11][11];
  for (int i = 0; i < n; ++i) memcpy(tmp[i], s[i], m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%c", tmp[i][j]);
    }
    printf("\n");
  }
  getchar();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (tmp[i][j] == 'W') {
        if (i != 0 && tmp[i - 1][j] == 'P') {
          tmp[i - 1][j] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (i != n - 1 && tmp[i + 1][j] == 'P') {
          tmp[i + 1][j] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (j != 0 && tmp[i][j - 1] == 'P') {
          tmp[i][j - 1] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
        if (j != m - 1 && s[i][j + 1] == 'P') {
          tmp[i][j + 1] = '.';
          tmp[i][j] = '.';
          dfs(tmp, n, m, eaten + 1, pigsleft - 1, besteaten);
        }
      }
    }
  }
}
int main() {
  {
    _fin = fopen("input.txt", "r");
    if (_fin == NULL) _fin = stdin;
  };
  int n = readi();
  int m = readi();
  static char s[11][11];
  for (int i = 0; i < n; ++i) reads(s[i], 11);
  int nwolfcaneat = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'W') {
        int pigcount = 0;
        if (i != 0 && s[i - 1][j] == 'P') pigcount++;
        if (i != n - 1 && s[i + 1][j] == 'P') pigcount++;
        if (j != 0 && s[i][j - 1] == 'P') pigcount++;
        if (j != m - 1 && s[i][j + 1] == 'P') pigcount++;
        if (pigcount != 0) nwolfcaneat++;
      }
    }
  }
  fprintf(_fout, "%d\n", nwolfcaneat);
  return 0;
}

```