# your code goes here
n, m=map (int, input (). split ())
house=[]
place={}
rev_place={}
sz=0
for i in range (n) :
house.append(input ())
for j in range (m) :
if(house[i][j] ==".") :
place[sz]=i*m+j
rev_place[place[sz]]=sz
sz+=1
from decimal import *
from decimal import Decimal as d
getcontext().prec=1450
matrix=[[d(0) for i in range (sz)] for i in range (sz)]
for x in range (sz):
order=place[x]
i=order//m
j=order%m
if(j>0 and house[i][j-1]=='.'):
matrix[x][x]-=d(1)
matrix[x][rev_place[i*m+j-1]]=d(1)
if(i>0 and house[i-1][j]=='.'):
matrix[x][x]-=d(1)
matrix[x][rev_place[(i-1)*m+j]]=d(1)
if(j<m-1 and house[i][j+1]=='.'):
matrix[x][x]-=d(1)
matrix[x][rev_place[i*m+j+1]]=d(1)
if(i<n-1 and house[i+1][j]=='.'):
matrix[x][x]-=d(1)
matrix[x][rev_place[(i+1)*m+j]]=d(1)
det=d(1)
row=0
col=0
eps=d(1)/d(10000000)
while (row<sz-1 and col<sz) :
max_abs=abs(matrix[row][col])
next_row=row
for i in range (row+1,sz):
cur_abs=abs(matrix [i][col])
if(cur_abs>max_abs):
max_abs=cur_abs
next_row=i
if(max_abs<eps):
col+=1
continue
for i in range (sz) :
matrix[row] [i], matrix[next_row] [i] =matrix[next_row] [i], matrix[row] [i]
for i in range (row+1,sz):
coeff=matrix [i] [col]/matrix[row] [col]
for j in range (col, sz) :
matrix [i][j]-=coeff*matrix[row][j]
row+=1
col+=1
size=sz
while(sz>1 and abs(matrix[sz-1][sz-1])<eps):
sz-=1
for i in range (sz) :
det*=d(abs(matrix[i][i])+eps)
M=1000*1000*1000
ans=(int(det+eps))%M
if(size==1):
ans=1
print(ans)
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCm4sIG09bWFwIChpbnQsIGlucHV0ICgpLiBzcGxpdCAoKSkgCmhvdXNlPVtdCnBsYWNlPXt9CnJldl9wbGFjZT17fSAKc3o9MApmb3IgaSBpbiByYW5nZSAobikgOgogICAgaG91c2UuYXBwZW5kK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