class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) w,h = map(int,input().split()) mod = 998244353; uf = UF(w+10); c = w for _ in range(h): s = [[] for _ in range(26)] for i,v in enumerate(input()): a = ord(v) if 48<=a<=57 and not uf.s(i,w+a-48): uf.u(i,w+a-48); c -= 1 if 97<=a<=122: s[a-97].append(i) for t in s: for u,v in zip(t[:-1],t[1:]): if not uf.s(u,v): uf.u(u,v); c -= 1 if len(set(uf.f(w+i) for i in range(10)))<10: c = -1 print(pow(10,c,mod) if c>=0 else 0)