116_B. Little Pigs and Wolves
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>
```python
n,m = map(int,input().split())
x,cnt = [],0
for _ in range(n):
	s = list(map(str,input()))
	for i in s:
		x.append(i)
if n==m==1: print(0)
elif n==1 or m==1:
	for i in range(len(x)):
		if x[i]=='W':
			if i==0:
				if x[i+1]=='P': x[i+1]='.';cnt+=1
			elif i==(len(x)-1):
				if x[i-1]=='P': x[i-1]='.';cnt+=1
			else:
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+1]=='P': x[i+1]='.';cnt+=1
	print(cnt)
else:
	for i in range(len(x)):
		if x[i]=='W' and m>1:
			if i==0:
				if x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
			elif i==m-1:
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
			elif i==m*(n-1):
				if x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
			elif i==(n*m)-1:
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
			elif i in range(1,m):
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
			elif i in range((m*(n-1))+1,n*m-1):
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
			elif i in range(m,m*(n-1),m):
				if x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
			elif i in range(2*m-1,n*m-1,m):
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
			else:
				if x[i-1]=='P': x[i-1]='.';cnt+=1
				elif x[i+1]=='P': x[i+1]='.';cnt+=1
				elif x[i+m]=='P': x[i+m]='.';cnt+=1
				elif x[i-m]=='P': x[i-m]='.';cnt+=1
	print(cnt)
```