inf = open("park.in", "r")
ouf = open("park.out", "w")

MOD = 10**9 + 9

h, w = map(int, inf.readline().split())

a = [inf.readline().strip() for i in range(h)]

for i in range(h):
	for j in range(w):
		if a[i][j] == 'E':
			si = i
			sj = j
		if a[i][j] == 'X':
			ti = i
			tj = j

c = [[[1 if k == 0 and a[i][j] == 'E' else 0 for j in range(w)] for i in range(h)] for k in range(2)]
d = [[0 if a[i][j] == 'E' else -1 for j in range(w)] for i in range(h)]
d2 = [[False for j in range(w)] for i in range(h)]

q = [(si, sj, 0)]
head = 0

di = [-1, 0, 1, 0]
dj = [0, -1, 0, 1]

while head < len(q):
	i, j, l = q[head]
	head += 1

	for k in range(4):
		ni = i + di[k]
		nj = j + dj[k]
		if ni >= 0 and ni < h and nj >= 0 and nj < w and a[ni][nj] != '#':
			if l == 0:
				if d[ni][nj] == -1:
					d[ni][nj] = d[i][j] + 1
					c[0][ni][nj] = (c[0][ni][nj] + c[0][i][j])
					q.append((ni, nj, 0))
				elif d[ni][nj] == d[i][j] + 1:
					d[ni][nj] = d[i][j] + 1
					c[0][ni][nj] = (c[0][ni][nj] + c[0][i][j])
				elif d[ni][nj] == d[i][j] - 1:
					c[1][ni][nj] = (c[1][ni][nj] + c[0][i][j])
					if not d2[ni][nj]:
						d2[ni][nj] = True
						q.append((ni, nj, 1))
			else:
				if d[ni][nj] == d[i][j] + 1:
					c[1][ni][nj] = (c[1][ni][nj] + c[1][i][j])
					if not d2[ni][nj]:
						d2[ni][nj] = True
						q.append((ni, nj, 1))

print(c[1][ti][tj] % MOD, file=ouf)
