MOD = 998244353 W,H = map(int,input().split()) P = [-1] * W def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x,y): x = root(x) y = root(y) if x == y: return if x > y: x,y = y,x P[x] += P[y] P[y] = x if y in code and x not in code: code[x] = code[y] code.pop(y) elif x in code and y in code: if code[x] == code[y]: code.pop(y) else: return False return True def same(x,y): return root(x) == root(y) from collections import defaultdict code = {} flag = 1 for h in range(H): if flag == 0: print(0) continue S = input() dic = defaultdict(list) for i in range(W): ri = root(i) s = S[i] x = ord(s) if 48 <= x <= 57: x -= 48 if ri in code: if code[ri] != x: flag = 0 print(0) break else: code[ri] = x if 97 <= x <= 122: dic[s].append(i) #print(i,P,code,flag) if flag == 1: for _,V in dic.items(): if len(V) > 1: v0 = V[0] for v in V[1:]: if unite(v0,v) == False: flag = 0 print(0) break if flag == 0: break if flag == 1: cnt = 0 ans = 1 for i in range(W): if P[i] < 0 and i not in code: cnt += 1 print(pow(10,cnt,MOD))