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>
import java.io.*;
import java.math.*;
import java.util.*;

 
 
 
public class B {
 
    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static long H,W;
    static BitSet bs;
    static long mod = 1000000007;
      // All possible moves of a knight 
    static   int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 }; 
    static int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 }; 
    static int [] dr   = {-1,0,0,1};
    static int [] dc = {0,1,-1,0};
   
    public static void main(String args[]) throws IOException {
    /**
1.What is the unknown:
2.What are the data: 
3.What is the condition:
4.What is the restriction: 
5. understand the problem:
6. What are the cases edges in the problem:
7.What what max:
8. Are you ssuing a data stcuture. And which one:
9.Is there reursion what is the base case. For example COINS:
*/
       int n = in.nextInt();
       int m= in.nextInt();
       char [] [] grid = new char[n][m];
       for(int i=0;i<n;i++){
           grid[i] = in.next().toCharArray();
       }
       int cnt =0;
       for(int i=0;i<n;i++){
           for(int j=0;j<m;j++){
               if(grid[i][j]=='W'){
                   for(int k=0;k<4;k++){
                       int nr = dr[k]+i;
                       int nc = dc[k]+j;
                       if(nr>=0&&nc<m&&nr<n&&nc>=0&&grid[nr][nc]=='P'){
                        cnt++;
                        grid[nr][nc] = 'o';
                        break;
                       }
                   }
               }
           }
       }
       out.println(cnt);
            out.flush();
    }
    


    

    static boolean isVowel(char c) {
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){
            return true;
        }
        return false ;
    }
    static class IP implements Comparable<IP>{
        public int first,second;
        IP(int first, int second){
            this.first = first;
            this.second = second;
        }
        public int compareTo(IP ip){
            if(first==ip.first)
                return second-ip.second;
            return first-ip.first;    
        }
        @Override
        public String toString() {
            return first+" "+second;
        }
 
    }
        
       static long gcd(long a, long b){
        return b!=0?gcd(b, a%b):a;
    }
 
        static boolean isEven(long a) {
            return (a&1)==0;
        }
    
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}