{ vim: set nospell:
}

const
  max = 500;
  modulo = 1000000009;
  dh: array[1..4] of longint = (1, 0, -1, 0);
  dw: array[1..4] of longint = (0, 1, 0, -1);

type
  event = record
    d: longint;
    h, w, t: longint;
  end;

var
  h, w: longint;
  a: array[1..max, 1..max] of char;
  d: array[1..max, 1..max] of longint;
  r: array[1..max, 1..max, 0..2] of longint;
  qh, qw: array[1..max*max] of longint;
  st_h, st_w, fi_h, fi_w: longint;
  i, j, k, ql, qr, dt, dp, dx: longint;
  th, tw, ch, cw: longint;
  events: array[1..max*max*3] of event;
  n: longint;

procedure qsort( l, r: longint );
var
  i, j: longint;
  x, t: event;
begin
  if l >= r then
    exit;
  x := events[l + random(r - l + 1)];
  i := l;
  j := r;
  while i <= j do begin
    while events[i].d < x.d do
      inc(i);
    while events[j].d > x.d do
      dec(j);
    if i <= j then begin
      t := events[i];
      events[i] := events[j];
      events[j] := t;
      inc(i);
      dec(j);
    end;
  end;
  qsort(l, j);
  qsort(i, r);
end;

begin
  assign(input, 'park.in');
  reset(input);
  assign(output, 'park.out');
  rewrite(output);

  readln(h, w);
  for i := 1 to h do
    for j := 1 to w do begin
      repeat
        read(a[i, j]);
      until a[i, j] in ['#', '.', 'E', 'X'];
      if a[i, j] = 'E' then begin
        st_h := i;
        st_w := j;
      end;
     if a[i, j] = 'X' then begin
        fi_h := i;
        fi_w := j;
      end;
      d[i, j] := 1000000000;
      for k := 0 to 2 do
        r[i, j, k] := 0;
    end;

  ql := 0;
  qr := 0;
  d[st_h, st_w] := 0;
  inc(qr);
  qh[qr] := st_h;
  qw[qr] := st_w;
  n := 0;
  while ql < qr do begin
    inc(ql);
    th := qh[ql];
    tw := qw[ql];
    for dp := 0 to 2 do begin
      inc(n);
      events[n].d := d[th, tw] + dp;
      events[n].h := th;
      events[n].w := tw;
      events[n].t := dp;
    end;
    for dt := 1 to 4 do begin
      ch := th + dh[dt];
      cw := tw + dw[dt];
      if (ch < 1) or (ch > h) or (cw < 1) or (cw > w) then
        continue;
      if a[ch, cw] = '#' then
        continue;
      if d[ch, cw] <= d[th, tw] + 1 then
        continue;
      d[ch, cw] := d[th, tw] + 1;
      inc(qr);
      qh[qr] := ch;
      qw[qr] := cw;
    end;
  end;

  qsort(1, n);
  r[st_h, st_w, 0] := 1;
  for i := 1 to n do begin
    th := events[i].h;
    tw := events[i].w;
    dp := events[i].t;
    for dt := 1 to 4 do begin
      ch := th + dh[dt];
      cw := tw + dw[dt];
      if (ch < 1) or (ch > h) or (cw < 1) or (cw > w) then
        continue;
      if a[ch, cw] = '#' then
        continue;
      dx := d[th, tw] + dp + 1 - d[ch, cw];
      assert(dx >= 0);
      if dx > 2 then
        continue;
      r[ch, cw, dx] := (r[ch, cw, dx] + r[th, tw, dp]) mod modulo;
    end;
  end;

  writeln(r[fi_h, fi_w, 2]);

  close(input);
  close(output);
end.

