import java.io.*;
import java.util.StringTokenizer;

public class tictactoe_dk {
    char[][] c;
    int[][] win;
    int[] dx = {-1, -1, 0, 1, 1, 1, 0, -1};
    int[] dy = {0, -1, -1, -1, 0, 1, 1, 1};

    int n, m;

    boolean checkChar(int i, int j, char ch) {
        if (change && i == qx && j == qy) {
            return (cc == ch);
        }
        if (i < 0 || i >= n || j < 0 || j >= m) {
            return ('.' == ch);
        }
        //System.err.println(i + " " + j + " " + n + " " + m);
        return (ch == c[i][j]);
    }
    int qx, qy;char cc;
    boolean change = false;
    boolean isWeWinIfWeGo(int x, int y) {

        if (checkChar(x, y, '.')) {
            qx = x;
            qy = y;
            cc = 'X';
            change = true;
        }
        int[] tic;
        int p = 0;
        for (int i = x - 6; i <= x + 6; i++) {
            next:
            for (int j = y - 6; j <= y + 6; j++) {
                if (checkChar(i, j, '.')) {
                    tic = new int[8];
                    for (int v = 0; v < 8; v++) {
                        int i1 = i;
                        int j1 = j;
                        while (checkChar(i1 + dx[v], j1 + dy[v], 'X')) {
                            tic[v]++;
                            i1 += dx[v];
                            j1 += dy[v];
                        }
                    }
                    for (int v = 0; v < 4; v++) {
                        if (1 + tic[v] + tic[v + 4] >= 5) {
                            p++;
                            continue next;
                        }
                    }
                }
            }
        }
        change = false;
        return p > 1;
    }

    boolean alreadyWin(int x, int y) {

        if (checkChar(x, y, '.')) {
            qx = x;
            qy = y;
            cc = 'X';
            change = true;
        }
        int[] tic = new int[8];
        int p = 0;
        for (int v = 0; v < 8; v++) {
            int i1 = x;
            int j1 = y;
            while (checkChar(i1 + dx[v], j1 + dy[v], 'X')) {
                tic[v]++;
                i1 += dx[v];
                j1 += dy[v];
            }
        }
        for (int v = 0; v < 4; v++) {
            if (1 + tic[v] + tic[v + 4] >= 5) {
                if (change) {
                    c[x][y] = '.';
                }
                return true;
            }
        }
        change = false;
        return false;
    }

    int ti, tj;

    int alreadyLose() {
        int[] tic;
        int p = 0;
        for (int i = -6; i <= n + 6; i++) {
            next:
            for (int j = -6; j <= m + 6; j++) {
                if (checkChar(i, j, '.')) {
                    tic = new int[8];
                    for (int v = 0; v < 8; v++) {
                        int i1 = i;
                        int j1 = j;
                        while (checkChar(i1 + dx[v], j1 + dy[v], '0')) {
                            tic[v]++;
                            i1 += dx[v];
                            j1 += dy[v];
                        }
                    }
                    for (int v = 0; v < 4; v++) {
                        if (1 + tic[v] + tic[v + 4] >= 5) {
                            p++;
                            ti = i;
                            tj = j;
                            continue next;
                        }
                    }
                }
            }
        }
        return p;
    }

    public void solve() throws IOException {
        n = nextInt();
        m = nextInt();
        c = new char[n][m];
        win = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = nextLine();
            c[i] = s.toCharArray();
        }

        int wins = 0;
        //Check if we already win the game
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (c[i][j] == '.') {
                    if (alreadyWin(i, j)) {
                        wins++;
                        win[i][j] = 1;
                    }
                }
            }
        }
        if (wins > 0) {
            out.println(wins);
            return;
        }

        //Check if we already lost the game
        int canLose = alreadyLose();
        if (canLose > 1) {
            out.println(0);
            return;
        }

        //Check if we have only one possible course

        if (canLose == 1) {

                if (isWeWinIfWeGo(ti, tj)) {
                    out.println(1);
                } else {
                    out.println(0);
                }

            return;
        }

        for (int i = -2; i <= n + 1; i++) {
            for (int j = -2; j <= m + 1; j++) {
                if ((i >= 0 && j >= 0 && i < n && j < m) && (win[i][j] == 1 || c[i][j] != '.')) {
                    continue;
                }
                if (isWeWinIfWeGo(i, j)) {
                    wins++;
                }
            }
        }
        out.println(wins);
    }


    void run() throws IOException {
       /* br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);*/
        br = new BufferedReader(new FileReader("tictactoe.in"));
        out = new PrintWriter("tictactoe.out");
        solve();
        out.close();
        br.close();
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

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

    public static void main(String[] args) throws IOException {
        new tictactoe_dk().run();
    }


}
