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>
#!/usr/bin/env python
from __future__ import division, print_function
import math
import os
import sys
from sys import stdin,stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque
#sys.setrecursionlimit(10**5)
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
#-----------------------------------------------------------------

def regularbracket(t):
    p=0
    for i in t:
        if i=="(":
            p+=1
        else:
            p-=1
        if p<0:
            return False
    else:
        if p>0:
            return False
        else:
            return True

#-------------------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] <= key):
            count = mid+1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1
    return count
#------------------------------reverse string(pallindrome)
def reverse1(string):
    pp=""
    for i in string[::-1]:
        pp+=i
    if pp==string:
        return True
    return False
#--------------------------------reverse list(paindrome)
def reverse2(list1):
    l=[]
    for i in list1[::-1]:
        l.append(i)
    if l==list1:
        return True
    return False
# endregion
import math
def mex(list1):
    #list1 = sorted(list1)
    p = max(list1)+1
    for i in range(len(list1)):
        if list1[i]!=i:
            p = i
            break
    return p
#----endregion
"""
def main():
    n,m = map(int,input().split())
    np = list(map(int,input().split()))
    mp = list(map(int,input().split()))
    np = sorted(np)
    mp = sorted(mp)
    cnt=0
    for i in np:
        if len(mp)==0:
            cnt+=1
        elif i in mp:
            continue
        elif i>max(mp):
            cnt+=1
        elif i<max(mp):
            #cnt-=1
            for j in mp:
                if j>i:
                    mp.remove(j)
                    break
    print(cnt)
"""
"""
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    max=0
    if len(arr)==1:
        print(1)
    elif len(arr)==2:
        print(2)
    else:
        cnt=2
        for i in range(n-2):
            if arr[i+2]==arr[i+1]+arr[i]:
                cnt+=1
            else:
                if cnt>max:
                    max = cnt

                cnt=2
        if cnt>max:
            max=cnt
        print(max)
"""
"""
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    arr = sorted(arr)
    p=0
    if len(arr)%2!=0:
        c = (math.pi)*(pow(arr[0],2))
        arr.pop(0)
        i=0
        p=0
        while(i<len(arr)-1):
            p+=(math.pi*(pow(arr[i+1],2))) - ((math.pi*(pow(arr[i],2))))
            i+=2
        print(p+c)
    else:
        i=0
        while(i<len(arr)-1):
            p += (math.pi * (pow(arr[i + 1], 2))) - ((math.pi * (pow(arr[i], 2))))
            i+=2
        print(p)
"""
"""
def main():
    n,m = map(int,input().split())
   # a,b = map(int,input().split())
    flag=[False]*(n+1)
    for i in range(m):
        a,b = map(int,input().split())
        flag[a]=True
        flag[b]=True
    x=1
    while(flag[x]):
        x+=1
    else:
        print(n-1)
    for i in range(1,x):
        print(i,x)
    for i in range(x+1,n+1):
        print(x,i)
"""
def main():
    n,m = map(int,input().split())
    l=[]
    l.append("0"*(m+2))
    for i in range(n):
        s = input()
        s ="0"+s+"0"
        l.append(s)
    l.append("0"*(m+2))
    cnt=0
    #print(l)
    for i in range(1,n+1):
        for j in range(1,m+1):
            if l[i][j]=="W":
                if (l[i - 1][j] == 'P' or l[i + 1][j] == 'P' or l[i][j - 1] == 'P' or l[i][j + 1] == 'P'):
                    cnt+=1
    print(cnt)
    """
    for i in range(n):
        for j in range(m):
            if l[i][j]=="W":
                if i==0:
                    if j==0:
                        if i+1<n and j+1<m:
                            if l[i+1][j]=="P":
                                cnt+=1
                                l[i+1][j]="."
                            elif l[i][j+1]=="P":
                                cnt+=1
                                l[i][j+1]="."
                    elif j==m-1:
                        #if i+1<=n and j-1>=0:
                            if l[i+1][j]=="P":
                                cnt+=1
                                l[i+1][j]="."
                            elif l[i][j-1]=="P":
                                cnt+=1
                                l[i][j-1]="."
                    else:
                        #if i+1<=n and j+1<m and j-1>=0:
                            if l[i][j+1]=="P":
                                cnt+=1
                                l[i][j+1]="."
                            elif l[i][j-1]=="P":
                                cnt+=1
                                l[i][j-1]="."
                            elif l[i+1][j]=="P":
                                cnt+=1
                                l[i+1][j]="."
                elif i==n-1:
                    if j==0:
                        #if i-1>=0 and j+1<m:
                            if l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."
                            elif l[i][j+1]=="P":
                                cnt+=1
                                l[i][j+1]="."
                    elif j==m-1:
                        #if i-1>=0 and j-1>=0:
                            if l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."
                            elif l[i][j-1]=="P":
                                cnt+=1
                                l[i][j-1]="."
                    else:
                        #if i-1>=0 and i>=0 and i<=n and j+1<m and j-1>=0:
                            if l[i][j+1]=="P":
                                cnt+=1
                                l[i][j+1]="."
                            elif l[i][j-1]=="P":
                                cnt+=1
                                l[i][j-1]="."
                            elif l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."
                else:
                    if j==0:
                        #if i+1<=n and j+1<m and i-1>=0:
                            if l[i+1][j]=="P":
                                cnt+=1
                                l[i+1][j]="."
                            elif l[i][j+1]=="P":
                                cnt+=1
                                l[i][j+1]="."
                            elif l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."
                    elif j==m-1:
                       # if i+1<=n and j-1>=0 and i-1>=0:
                            if l[i+1][j]=="P":
                                cnt+=1
                                l[i+1][j]="."
                            elif l[i][j-1]=="P":
                                cnt+=1
                                l[i][j-1]="."
                            elif l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."

                    else:
                        #if i+1<=n and i-1>=0 and j+1<m and j-1>=0:
                            if l[i][j + 1] == "P":
                                cnt += 1
                                l[i][j + 1] = "."
                            elif l[i][j - 1] == "P":
                                cnt += 1
                                l[i][j - 1] = "."
                            elif l[i + 1][j] == "P":
                                cnt += 1
                                l[i + 1][j] = "."
                            elif l[i-1][j]=="P":
                                cnt+=1
                                l[i-1][j]="."
    print(cnt)
"""
if __name__ == '__main__':
    main()