class Unionfind: def __init__(self,n): self.uf = [-1]*n self.ps = [-2]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def update(self,x,nx): x = self.find(x) ny = self.ps[x] if nx != ny: if nx != -2 and ny != -2: self.ps[x] = -1 else: self.ps[x] = max(nx,ny) def union(self,x,y): x = self.find(x) y = self.find(y) nx = self.ps[x] ny = self.ps[y] if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x if nx != ny: if nx != -2 and ny != -2: self.ps[x] = -1 else: self.ps[x] = max(nx,ny) return True def size(self,x): x = self.find(x) return -self.uf[x] w,h = map(int,input().split()) mod = 998244353 uf = Unionfind(w) for i in range(h): q = input() last = [-1]*26 for j in range(w): s = q[j] if "0" <= s <= "9": uf.update(j,int(s)) elif "a" <= s <= "z": pos = ord(s)-ord("a") if last[pos] == -1: last[pos] = j else: uf.union(last[pos],j) ans = 1 for j in range(w): if uf.find(j) == j: num = uf.ps[j] if num == -2: ans *= 10 elif num == -1: ans = 0 break ans %= mod print(ans)