def root(x): p=x l=[p] while r[p]!=p: p=r[p] l+=[p] for p in l: r[p]=l[-1] return r[x] def union(x,y): rx=root(x) ry=root(y) if rx==ry: return if rx>ry: rx,ry=ry,rx r[ry]=rx return h,w=map(int,input().split()) s=[input() for i in range(h)] r=list(range(h*w)) M=998244353 c=1 for i in range(h): for j in range(w): if s[i][j]=="#": c*=2 if i-1>=0 and j-1>=0 and root((i-1)*w+j)==root(i*w+(j-1)) else 4 c%=M if i-1>=0 and s[i-1][j]=="#": union(i*w+j,(i-1)*w+j) if j-1>=0 and s[i][j-1]=="#": union(i*w+j,i*w+(j-1)) print(c)