from sys import stdin input=lambda :stdin.readline()[:-1] from collections import defaultdict class UnionFind(): def __init__(self,n): self.n=n self.parents=[-1]*n self.grp_cnt=n def find(self,x): if self.parents[x]<0: return x else: self.parents[x]=self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x=self.find(x) y=self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x self.grp_cnt-=1 def size(self,x): return -self.parents[self.find(x)] def same(self,x,y): return self.find(x)==self.find(y) def members(self,x): root=self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i, x in enumerate(self.parents) if x< 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members=defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members mod=998244353 w,h=map(int,input().split()) uf=UnionFind(w+10) flag=False from collections import defaultdict for _ in range(h): s=input() if flag: continue d=defaultdict(list) for i in range(w): d[s[i]].append(i) for j in d: if '0'<=j<='9': for i in d[j]: uf.union(i,w+int(j)) else: if j=='?': continue for i in d[j]: uf.union(d[j][0],i) for i in range(10): for j in range(i+1,10): if uf.same(w+i,w+j): flag=True if flag: print(0) else: g=uf.all_group_members() c=len(g)-10 print(pow(10,c,mod))