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.awt.Point;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class B {

    public static void main(String[] Args) throws IOException {
        new B().solve();
    }

    int o = INF;
    int n;
    static int[] dx_ = { 0, 0, 1, -1 };
    static int[] dy_ = { 1, -1, 0, 0 };

    void solve() throws IOException {
        int n = si(), m = si();
        char[][] a = new char[n][m];
        for (int i = 0; i < a.length; i++) {
            String s = ss();
            for (int j = 0; j < s.length(); j++) {
                a[i][j] = s.charAt(j);
            }
        }
        o = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] == 'W')
                    for (int k = 0; k < 4; k++) {
                        int x = i + dx_[k], y = j + dy_[k];
                        if (0 <= x && x < n && 0 <= y && y < m)
                            if (a[x][y] == 'P') {
                                o++;
                                break;
                            }
                    }
            }
        }
        System.out.println(o);
    }

    String[] toStr = new String[5 + (int) 1e6];
    HashMap<String, Integer> toInt = new HashMap<String, Integer>();

    class num {
        char[] cs = new char[(int) 1e4];
        int size = 1;

        public num() {
            cs[0] = 'A';
            toStr[1] = "A";
        }

        void inc() {
            inc(cs, 0);
        }

        int inc(char[] cs, int p) {
            if ('A' <= cs[p] && cs[p] <= 'Z')
                cs[p]++;
            else {
                cs[p] = 'A';
                size++;
            }
            if (cs[p] > 'Z') {
                cs[p] = 'A';
                p++;
                inc(cs, p);
            }
            return p;
        }

        @Override
        public String toString() {
            String s = "";
            for (int i = size - 1; i >= 0; i--) {
                s += cs[i];
            }
            return s;
        }
    }

    /**
     * important for speed!!! PrintWriter out=new PrintWriter(new
     * OutputStreamWriter(System.out)); out.close();
     * 
     * @param v
     */
    void dfs(LinkedList<Integer> v) {
        if (ok(v)) {
            o = Math.min(o, n - v.size());
        } else {
            LinkedList<Integer> first = new LinkedList<Integer>(v);
            LinkedList<Integer> last = new LinkedList<Integer>(v);

            remove(first, true);
            remove(last, false);

            dfs(first);
            dfs(last);
        }
    }

    boolean ok(LinkedList<Integer> v) {
        if (v.size() == 0)
            return false;
        if (v.size() == 1)
            return true;
        int x = v.get(0), y = v.get(v.size() - 1);
        return y <= 2 * x;
    }

    void remove(LinkedList<Integer> v, boolean first) {
        if (v.size() > 0) {
            if (first) {
                Integer val = v.removeFirst();
                while (v.size() > 0 && v.getFirst().equals(val)) {
                    v.removeFirst();
                }
            } else {
                Integer val = v.removeLast();
                while (v.size() > 0 && v.getLast().equals(val)) {
                    v.removeLast();
                }
            }
        }
    }

    // ----------------------- Library ------------------------
    /**
     * important for speed!!! PrintWriter out=new PrintWriter(new
     * OutputStreamWriter(System.out)); out.print(...); out.close();
     * 
     * @param v
     */
    // leap year is 29
    int[] year = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    void initSystem() throws IOException {
        if (br != null)
            br.close();
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    void initFile() throws IOException {
        if (br != null)
            br.close();
        br = new BufferedReader(new InputStreamReader(new FileInputStream(
                "input.txt")));
    }

    void printWriter() {
        try {
            PrintWriter pr = new PrintWriter("output.txt");
            pr.println("hello world");
            pr.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    void comparator() {
        Point[] v = new Point[10];
        Arrays.sort(v, new Comparator<Point>() {
            @Override
            public int compare(Point a, Point b) {
                if (a.x != b.x)
                    return -(a.x - b.x);
                return a.y - b.y;
            }
        });
    }

    double distance(Point a, Point b) {
        double dx = a.x - b.x, dy = a.y - b.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    Scanner in = new Scanner(System.in);

    String ss() {
        return in.next();
    }

    String sline() {
        return in.nextLine();
    }

    int si() {
        return in.nextInt();
    }

    int[] sai(int n) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    int[] sai_(int n) {
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    BufferedReader br;
    StringTokenizer tokenizer;
    {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    void tok() throws IOException {
        tokenizer = new StringTokenizer(br.readLine());
    }

    int toki() throws IOException {

        return Integer.parseInt(tokenizer.nextToken());
    }

    int[] rint(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++)
            a[i] = Integer.parseInt(tokenizer.nextToken());

        return a;
    }

    int[] rint_(int n) throws IOException {
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = Integer.parseInt(tokenizer.nextToken());

        return a;
    }

    String[] rstrlines(int n) throws IOException {
        String[] a = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = br.readLine();
        }
        return a;
    }

    long tokl() {
        return Long.parseLong(tokenizer.nextToken());
    }

    double tokd() {
        return Double.parseDouble(tokenizer.nextToken());
    }

    String toks() {
        return tokenizer.nextToken();
    }

    String rline() throws IOException {
        return br.readLine();
    }

    List<Integer> toList(int[] a) {
        List<Integer> v = new ArrayList<Integer>();
        for (int i : a)
            v.add(i);
        return v;
    }

    static void pai(int[] a) {
        System.out.println(Arrays.toString(a));
    }

    static int toi(Object s) {
        return Integer.parseInt(s.toString());
    }

    static int[] dx3 = { 1, -1, 0, 0, 0, 0 };
    static int[] dy3 = { 0, 0, 1, -1, 0, 0 };
    static int[] dz3 = { 0, 0, 0, 0, 1, -1 };

    static int[] dx = { 1, 0, -1, 1, -1, 1, 0, -1 }, dy = { 1, 1, 1, 0, 0, -1,
            -1, -1 };

    static int INF = 2147483647; // =2^31-1 // -8
    static long LINF = 922337203854775807L; // -8
    static short SINF = 32767; // -32768

    // finds GCD of a and b using Euclidian algorithm
    public int GCD(int a, int b) {
        if (b == 0)
            return a;
        return GCD(b, a % b);
    }

    static List<String> toList(String[] a) {
        return Arrays.asList(a);
    }

    static String[] toArray(List<String> a) {
        String[] o = new String[a.size()];
        a.toArray(o);
        return o;
    }

    static int[] pair(int... a) {
        return a;
    }
}
