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

public class park_bm {
    FastScanner in;
    PrintWriter out;

    long mod = (long) 1e9 + 9;

    class Field implements Comparable<Field> {
        int time, x, y;

        Field(int time, int x, int y) {
            this.time = time;
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Field o) {
            return Integer.compare(time, o.time);
        }

    }

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++)
            s[i] = in.next();
        int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                char c = s[i].charAt(j);
                if (c == 'X') {
                    x1 = i;
                    y1 = j;
                }
                if (c == 'E') {
                    x2 = i;
                    y2 = j;
                }
            }
        int[] qx = new int[n * m];
        int[] qy = new int[n * m];
        int[][] d = new int[n][m];
        for (int i = 0; i < n; i++)
            Arrays.fill(d[i], Integer.MAX_VALUE / 2);
        d[x1][y1] = 0;
        int sz = 1;
        qx[0] = x1;
        qy[0] = y1;
        int it = 0;
        int[] dx = { -1, 0, 0, 1 };
        int[] dy = { 0, -1, 1, 0 };
        while (it < sz) {
            int x = qx[it];
            int y = qy[it++];
            for (int iter = 0; iter < 4; iter++) {
                int nx = x + dx[iter];
                int ny = y + dy[iter];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx].charAt(ny) != '#') {
                    if (d[nx][ny] > d[x][y] + 1) {
                        d[nx][ny] = d[x][y] + 1;
                        qx[sz] = nx;
                        qy[sz++] = ny;
                    }
                }
            }
        }
        long[][][] ans = new long[3][n][m];
        ans[0][x1][y1] = 1;
        ArrayList<Field> fields = new ArrayList<>();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (d[i][j] != Integer.MAX_VALUE / 2)
                    for (int k = 0; k < 3; k++)
                        fields.add(new Field(d[i][j] + k, i, j));
        Collections.sort(fields);
        for (Field f : fields) {
            int x = f.x;
            int y = f.y;
            int k = f.time - d[x][y];
            for (int j = 0; j < 4; j++) {
                int nx = x + dx[j];
                int ny = y + dy[j];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx].charAt(ny) != '#') {
                    int mm = f.time + 1 - d[nx][ny];
                    if (mm < 3) {
                        ans[mm][nx][ny] += ans[k][x][y];
                        if (ans[mm][nx][ny] >= mod)
                            ans[mm][nx][ny] -= mod;
                    }
                }
            }
        }
        out.println(ans[2][x2][y2]);

    }

    void run() {
        try {
            in = new FastScanner(new File("park.in"));
            out = new PrintWriter(new File("park.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

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