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?
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.
2 3
PPW
W.P
2
3 3
P.W
.P.
W.P
0
1 1
P
0
2 6
WW..WW
.PPPP.
2
6 2
.W
.W
.P
WP
.P
PW
3
2 10
W..WWP.P.P
W..PP.WWP.
3
10 2
P.
.W
PW
..
W.
W.
..
P.
WP
PP
2
3 4
WPPW
.P..
PWW.
3
4 3
.WW
..P
P.P
PWW
3
3 10
WPPP...PP.
.P...WW..W
.WWP.PP.PW
6
10 3
...
PWW
..P
..P
P.P
WP.
PPW
..W
W..
WPP
5
4 8
..PW..WW
WWPP.PP.
P...PW.P
P.WW...P
5
8 4
P.WW
W..P
P..P
P.WW
..P.
W.P.
WP.W
P..P
6
1 1
W
0
4 10
..P.PW.P.P
P.WP.W..WP
W..P.P..WP
W.PWW.P.P.
7
10 4
WPPP
P.PW
...W
W..P
..W.
.PP.
W..P
W.PW
..P.
PPW.
6
5 1
.
P
.
.
W
0
5 10
P.PPWWP.PP
.W....P.PP
PWPP..WW..
...W..P.P.
WP.W...PWW
7
10 5
..PWW
WWP.P
.PP..
P..WW
PW...
.W..P
..P.W
P.PP.
W..WP
WPPP.
8
6 5
..WP.
WP..W
W.PP.
.PWW.
P.PPP
WP..W
6
5 6
P...PW
.WWP.W
.P...P
WP..W.
WPPPWP
7
6 10
PPP.WW..PW
.W.....WP.
.W.PP..WP.
.PP..WPP.P
W.PW.P.PWW
WP.P..P.P.
10
10 6
.WW.PW
......
WP..W.
PPWP.P
.PW.PW
PP.P.W
P.PWPP
W..W.P
WPP..W
.PWP.W
11
7 3
WPP
W.P
...
PWP
PW.
..P
..W
4
3 7
WP...PW
.PW.P..
PPW.PW.
5
7 10
W..W.PWW.P
W.P.P.PP.W
P...W.....
PWPPW..WW.
....PPP..P
WP.WPP.P.P
PP..PWP.WW
11
10 7
.PW..WP
W...PW.
..PW...
PW..PP.
.W.P.WW
.P.P...
P.PPW..
.PW...P
W.P.PPP
W.PPWPP
10
8 8
WP.W...P
W.P..WW.
P.W.P.P.
PPPPPPPP
WW..WP.W
P.P.PP..
..WW..W.
PP....W.
9
8 10
PWW..P..W.
PP.PP...W.
WP..PWW.P.
P.P.....P.
PPW.P.P.WW
PPP.WW.PP.
W.P....P.P
..WWPPW..W
12
10 8
.PPW.PWW
W.PWP.P.
WP..PP..
..WP.PPP
..PP.WW.
.WP...P.
..PWW..W
W.P..PPW
...P...P
PWP.WWP.
12
9 8
PP..W..W
.PP.W..W
..W...PP
WP.P.WW.
W..W.P..
P.PP..P.
...PW.PP
.WPPW..W
PWP.PPPP
12
8 9
PWWPPW..W
P.P..WP.P
W..WPP.PP
P.PP....W
.....WWP.
P.WWP.P..
W......WW
PP.PWPP.P
13
10 10
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
0
9 10
W.PPWW..P.
W.P.....WP
P..W......
..P.PP.W.P
.PW.P..W..
..P...PPPP
PPP.W..PPP
WW.PW...PP
.PPP..WW.P
8
10 9
WWP.P.WPP
..PWP.P.W
....PWP..
WW...P.WP
.P.WP..W.
PP...W.P.
P.W..WP.W
.PWPP..P.
.PPPPPWW.
PW..W..PP
15
10 1
.
W
W
P
P
.
.
.
W
P
2
1 10
P.PW.PW..W
2
10 10
PWPP...PPW
.P.W...W..
W.P.PW....
P.P.PW..WP
PP.W.PP.P.
.P.P..WP.W
.WW.PPP..P
..P...PPP.
P.P..WW..W
.WWP...PPW
16
10 10
.PW...P.PW
....W..PPW
WWP.W..P.P
.P..PP.P..
...W...WW.
PWP..W....
PW...W..PW
.P..P.PP.P
PPPPWP..W.
PPPPP.W.PP
11
10 10
PP..PPWPPW
PPPPPPPP..
.PPPPPPP.P
PPPPPPPPPP
PWP.PPP.PP
PW.PP.PPPP
PPPPPP.PPW
..PPWPPP.P
WPPPPPPPPP
WP.WPPPWPP
10
10 10
PPPPPPPPPP
PPPPPPPWPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
1
10 10
PPPPPPPPWP
PPPWPPPPPP
PPPPPPPPPP
PWWPPWPPPP
PPPPPPPPPP
PPPPWPPPPP
PPPPPPPPPP
PPPPPPWPPW
PPPPPPPPPP
PPWPPPPPWP
10
10 10
.PWWP..W..
.....W...W
WP........
W...WP....
P.W..P..WW
..W...WP.P
W...W.....
....WP..P.
.W....W..W
.W....W..W
8
10 10
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWWWWWWWW
0
10 10
W..W..W...
W..P..W...
..W.....WW
....WW....
WW.....W..
.........W
..WW......
.......WW.
W.........
W..WW....W
1
10 10
..P..WWP.W
PP.WPPPPPP
WWPP.PPWPP
PPPPW..PPW
PP.PW.P.PW
WW..PPWWP.
..PW...PP.
.PPPP.PPPW
PP.PWP..P.
PWPPP..WWP
20
10 10
......W...
..........
..........
..........
..........
..........
..........
..........
..........
........P.
0
10 10
.P.PPPP..W
PWW.PPWPPW
...PPP.P..
W..P...WP.
.PPWPP.W..
...PPWPPPP
WP..PW..W.
PPW.....P.
P.P...PP.W
WPPWW.PPPW
14
10 10
W...W.....
..W...WW..
.........W
...WW....W
WW.....W..
.....W....
..W.....W.
W...W.....
W.....W..W
..WW..W..W
0
10 10
WW..W...WW
....W.....
......WW..
.W.....P..
.W...W..WW
...W......
W..W......
W....WW..P
P.........
...WW...WW
2
10 10
P.PPP.PP.P
PPP.PPP.P.
P.PPPP..PW
P.PPP.PP.P
PPPPPP.P.P
PPPP.PP.P.
.PPWPPPPP.
PPP...PPPP
PPP.PPPP.P
.WPPPP.P.P
3
1 4
W..P
0
10 10
P.W.P.W.P.
.W.P.W.P.W
P.W.P.W.P.
.W.P.W.P.W
P.W.P.W.P.
.W.P.W.P.W
P.W.P.W.P.
.W.P.W.P.W
P.W.P.W.P.
.W.P.W.P.W
0
10 10
WPPPWPPPWP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
WPPPWPPPWP
PPPPPPPPPP
PPPPPPPPPP
PPPPPPPPPP
WPPPWPPPWP
PPPPPPPPPP
9
10 10
PPPPPPPPPP
WWWWWWWWWW
WWWWWWWWWW
PPPPPPPPPP
PPPPPPPPPP
WWWWWWWWWW
WWWWWWWWWW
PPPPPPPPPP
PPPPPPPPPP
WWWWWWWWWW
50
4 1
.
W
P
.
1
1 10
P..W.PPWW.
1
10 1
P
P
W
W
.
P
.
.
.
W
1
1 1
.
0
10 10
PPPWPPPWPP
PWPPPWPPPP
PPPPPPPPPP
WPPWPPWPPW
PPPPPPPPPP
PWPPWPPWPP
PPPPPPPPPP
PPWPPWPPWP
PPPPPPPPPP
WPPWPPWPPW
18
10 10
WPPPPWPPWP
PPPWPPPPPP
PWPPPPWPPP
PPPPWPPPWP
WPPPPPPPPP
PPPWPPWPPP
PWPPPPPPWP
PPPPWPPPPP
WPPPPPWPPP
PPPWPPPPWP
18
4 4
.P..
.W..
.P..
..W.
1
4 1
.
.
W
P
1
10 10
WPPPPWPPWP
PPPWPPPPPP
PWPPPPWPPP
PPPPWPPPWP
WPPPPPPPPP
PPPWPPWPPP
PWPPPPPPWP
PPPPWPPPPP
WPPPPPWPPP
PPPWPPPPWP
18
3 3
PWP
...
W..
1
2 3
WWP
PPP
2
def main():
    n, m = list(map(int, input().split()))
    table = []
    table.append([-1] * (m+2))
    for i in range(n):
        temp = input()
        s = [-1]
        for j in temp:
            if j == 'P':
                s.append(0)
            elif j == 'W':
                s.append(1)
            else:
                s.append(-1)
        s.append(-1)
        table.append(s)
    table.append([-1] * (m+2))
    n += 2
    m += 2
    ans = 0
    for i in range(1, n-1):
        for j in range(1, m-1):
            if table[i][j] == 1:
                if table[i-1][j] == 0 or table[i+1][j] == 0 or table[i][j-1] == 0 or table[i][j+1] == 0:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()