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.io.PrintWriter;
import java.util.*;
import java.io.InputStream;
import java.io.DataInputStream;
 
 
 
public class Main
{
  //static{ System.out.println("hello");}
        static InputStream inputStream = System.in;
        static OutputStream outputStream = System.out;
        static FastReader scn = new FastReader(inputStream);
        static PrintWriter out = new PrintWriter(outputStream);
        static int fibo[]=new int[61];
        static int start;
        static void print(int a[])
         {        for (int i=0;i<a.length ;i++)
               {
                    out.print(a[i]+" ");   
               }   
        }   
        
        static int check(char ch[][], int n ,int m ,int x, int y)
        {          int pig=0;
                     if (y>=1 && y<=m && x-1>=1 && x-1<=n && ch[x-1][y]=='P' ){  pig++; }
                     
                     if (y-1>=1 && y-1<=m && x>=1 && x<=n && ch[x][y-1]=='P' ){  pig++; }
                     
                     if (y+1>=1 && y+1<=m && x>=1 && x<=n && ch[x][y+1]=='P'){  pig++; }
                     
                     if (y>=1 && y<=m && x+1>=1 && x+1<=n && ch[x+1][y]=='P' ){  pig++; }
                                                       
            return pig;
        }    
     
        public static void main(String[] args) throws IOException
       {    boolean visited[][]=new boolean[100][100];
             int n=scn.ni();
             int m=scn.ni();
             char ch[][]=new char[n+1][m+1];
             HashMap<Integer , ArrayList<num> > hm=new HashMap<Integer , ArrayList<num> >();
             for(int i=1;i<=n;i++)
             {  String temp=scn.ns();
                 for(int j=0;j<m;j++)
                   {
                      ch[i][j+1]=temp.charAt(j);  
                    }    
             }
             
             
              for(int i=1;i<=n;i++)
             {  
                 for(int j=1;j<=m;j++)
                   { if (ch[i][j]=='W')
                      {int cnt;
                     cnt= check(ch,n,m,i,j);
                     if (hm.containsKey(cnt)) hm.get(cnt).add(new num(i,j));
                     else {hm.put(cnt,new ArrayList<num>()); hm.get(cnt).add(new num(i,j)); }
                    }
                    }    
             }
             
             Set<Integer> ss=hm.keySet();
             ArrayList<Integer> arr=new  ArrayList<Integer>(ss);
             Collections.sort(arr);
             int pig=0;
           
             for(int q : arr)
             {  for(num n2 : hm.get(q))
                 {   int x=n2.ff; int y=n2.ss;
                     if (y>=1 && y<=m && x-1>=1 && x-1<=n && ch[x-1][y]=='P' && visited[x-1][y]==false){ visited[x-1][y]=true; pig++; continue;}
                     
                     if (y-1>=1 && y-1<=m && x>=1 && x<=n && ch[x][y-1]=='P' && visited[x][y-1]==false){ visited[x][y-1]=true; pig++; continue;}
                     
                     if (y+1>=1 && y+1<=m && x>=1 && x<=n && ch[x][y+1]=='P' && visited[x][y+1]==false){ visited[x][y+1]=true; pig++; continue; }
                     
                     if (y>=1 && y<=m && x+1>=1 && x+1<=n && ch[x+1][y]=='P' && visited[x+1][y]==false){ visited[x+1][y]=true; pig++; continue;}
                     
                    }
             
             }
             
             
             out.println(pig);
             out.close();
        }     
  
                    
         
}


  class num 
    {
        
        public int ff;
        public int ss;
   
        num()
        {
            
        }
        num(int x,int y)
        {
            this.ff = x;
            this.ss =y;
       
        }
        public int getff()
        {
        return ff;
        }
        public int getss()
        {
        return ss;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.ff==n.ff && this.ss==n.ss) return true;
        else return false;
            
            
        }
    }

class FastReader
{
 
    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
 
    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }
 
    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }
    
 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }
    
    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
 
                
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }
 
    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }
 
    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }
 
    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }
 
    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
 
    public String next()
    {
        return ns ();
    }
 
    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}     