note: This article comes from the Internet. Please contact me via lethic@163.com if there is any infringement.
lethic@163.com.

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 12738 Accepted: 4645

Description

N*MN*MNM “H” “P”

Input

NM
NM(‘P”H’)N <= 100M <= 10

Output

K

Sample Input

5 4
PHPP
PPHH
PPPP
PHPP
PHHP

Sample Output

6