#include <cassert>
#include <cstdio>
#include <cstring>

const int mod = (int)1e9 + 9;
int dd[5] = {0, 1, 0, -1, 0}, *dh = dd + 1, *dw = dd + 0;

int main() {
  assert(freopen("park.in", "r", stdin));
  assert(freopen("park.out", "w", stdout));

  int h, w;
  assert(scanf("%d%d", &h, &w) == 2);
  char a[h][w];
  int sh = -1, sw = -1, xh = -1, xw = -1;
  int qh[h * w], qw[h * w], d[h][w], ql = 0, qr = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      d[i][j] = (int)1e9;
      assert(scanf(" %c", &a[i][j]) == 1);
      if (a[i][j] == 'E') {
        sh = i, sw = j;
        a[i][j] = '.';
      }
      if (a[i][j] == 'X') {
        xh = i, xw = j;
        a[i][j] = '.';
      }
    }

  d[sh][sw] = 0;
  qh[qr] = sh, qw[qr] = sw;
  qr++;

  int mq = 0;
  while (ql < qr) {
    if (qr - ql > mq)
      mq = qr - ql;
    int i = qh[ql], j = qw[ql];
    ql++;
    for (int dt = 0; dt < 4; dt++) {
      int th = i + dh[dt];
      int tw = j + dw[dt];
      if (th < 0 || th >= h || tw < 0 || tw >= w)
        continue;
      if (a[th][tw] == '#')
        continue;
      if (d[th][tw] < (int)1e9)
        continue;
      d[th][tw] = d[i][j] + 1;
      qh[qr] = th, qw[qr] = tw;
      qr++;
    }
  }
  // fprintf(stderr, "mq = %d\n", mq);

  int res[h][w][3];
  memset(res, 0, sizeof(res[0][0][0]) * h * w * 3);
  res[sh][sw][0] = 1;
  int k[3] = {0, 0, 0};
  while (k[2] < qr) {
    int tk = -1, dk = -1;
    for (int tt = 0; tt < 3; tt++)
      if (k[tt] < qr) {
        int dt = d[qh[k[tt]]][qw[k[tt]]] + tk;
        if (tk != -1 && dt >= dk)
          continue;
        tk = tt;
        dk = dt;
      }
    assert(tk + 1);
    int i = qh[k[tk]], j = qw[k[tk]];
    k[tk]++;
    for (int dt = 0; dt < 4; dt++) {
      int th = i + dh[dt];
      int tw = j + dw[dt];
      if (th < 0 || th >= h || tw < 0 || tw >= w)
        continue;
      if (a[th][tw] == '#')
        continue;
      if (d[i][j] + tk + 1 > d[th][tw] + 2)
        continue;
      int td = d[i][j] + tk + 1 - d[th][tw];
      assert(0 <= td && td <= 2);
      res[th][tw][td] += res[i][j][tk];
      if (res[th][tw][td] >= mod)
        res[th][tw][td] -= mod;
    }
  }

  printf("%d\n", res[xh][xw][2]);

  return 0;
}

