import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class park_od_j {
  private static class Node {
    public int h, w;
    public Node( int h, int w ) {
      this.h = h;
      this.w = w;
    }
  }

  private static class State implements Comparable<State> {
    private int d;
    public int h, w, t;
    public State( int d, int h, int w, int t ) {
      this.d = d;
      this.h = h;
      this.w = w;
      this.t = t;
    }
    public int compareTo( State b ) {
      return d - b.d;
    }
  }

  private static final int mod = 1000000009;
  private static final int[] dh = {1, 0, -1, 0};
  private static final int[] dw = {0, 1, 0, -1};

  public static final void main( String[] args ) throws FileNotFoundException {
    Scanner in = new Scanner(new File("park.in"));
    PrintWriter out = new PrintWriter("park.out");

    int h = in.nextInt();
    int w = in.nextInt();
    int st_h = -1, st_w = -1;
    int fi_h = -1, fi_w = -1;
    char[][] a = new char[h][w];
    int[][] d = new int[h][w];
    for (int i = 0; i < h; i++) {
      String line = in.next();
      for (int j = 0; j < w; j++) {
        a[i][j] = line.charAt(j);
        if (a[i][j] == 'E') {
          st_h = i;
          st_w = j;
        }
        if (a[i][j] == 'X') {
          fi_h = i;
          fi_w = j;
        }
        d[i][j] = 1000000000;
      }
    }
    
    LinkedList <Node> queue = new LinkedList<Node>();
    ArrayList <State> st = new ArrayList<State>();
    d[st_h][st_w] = 0;
    queue.add(new Node(st_h, st_w));
    while (queue.size() != 0) {
      Node u = queue.removeFirst();
      for (int t = 0; t <= 2; t++)
        st.add(new State(d[u.h][u.w] + t, u.h, u.w, t));
      for (int dt = 0; dt < 4; dt++) {
        int th = u.h + dh[dt];
        int tw = u.w + dw[dt];
        if (th < 0 || tw < 0 || th >= h || tw >= w)
          continue;
        if (a[th][tw] == '#')
          continue;
        if (d[th][tw] <= d[u.h][u.w] + 1)
          continue;
        d[th][tw] = d[u.h][u.w] + 1;
        queue.add(new Node(th, tw));
      }
    }
    // System.out.println("dist: " + d[fi_h][fi_w]);

    Collections.sort(st);
    int[][][] r = new int[h][w][3];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        for (int t = 0; t < 3; t++)
          r[i][j][t] = 0;
    r[st_h][st_w][0] = 1;
    for (int i = 0; i < st.size(); i++) {
      State s = st.get(i);
      for (int dt = 0; dt < 4; dt++) {
        int th = s.h + dh[dt];
        int tw = s.w + dw[dt];
        if (th < 0 || tw < 0 || th >= h || tw >= w)
          continue;
        if (a[th][tw] == '#')
          continue;
        int dd = d[s.h][s.w] + s.t + 1 - d[th][tw];
        assert dd >= 0;
        if (dd > 2)
          continue;
        r[th][tw][dd] += r[s.h][s.w][s.t];
        r[th][tw][dd] %= mod;
      }
    }

    out.println(r[fi_h][fi_w][2]);
    out.close();
  }
}

