import sys input = sys.stdin.readline MOD=998244353 W,H=map(int,input().split()) class UnionFind: def __init__(self, n:int): self.n = n self.parents = [-1] * n def find(self, x:int): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x:int, y:int): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x if y<10: x,y=y,x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x:int): return -self.parents[self.find(x)] def same(self, x:int, y:int): return self.find(x) == self.find(y) uf = UnionFind(10+W) ans = pow(10, W, MOD) div10 = pow(10, MOD-2, MOD) for _ in range(H): Q=input().strip() check = {} for i,s in enumerate(Q,start=10): if s=="?":continue if "a"<=s<="z": if s in check: if uf.same(check[s], i): continue ca=uf.find(check[s]) ci=uf.find(i) if ca<10 and ci<10: ans=0 uf.union(check[s], i) ans = ans * div10 % MOD else: check[s] = i else: root = uf.find(i) s = int(s) if root < 10 and root != s: ans=0 if root != s: uf.union(s, i) ans = ans * div10 % MOD print(ans)