import sys input = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] W, H = map(int, input().split()) mod = 998244353 U = UnionFind(W) num = list(range(10)) num = set(list(map(str, num))) numlst = [-1] * W flag = 1 ans = pow(10, W, mod) for _ in range(H): S = list(input().rstrip("\n")) L = [[] for i in range(26)] cnt = 0 for i, s in enumerate(S): if s == "?": pass elif s in num: s = int(s) if numlst[U.find(i)] == -1: cnt += 1 numlst[U.find(i)] = s elif numlst[U.find(i)] != s: flag = 0 else: L[ord(s) - ord("a")].append(i) for j in range(26): if len(L[j]) <= 1: continue else: for k in range(1, len(L[j])): if U.is_same(L[j][0], L[j][k]): continue else: cnt += 1 Lj0 = U.find(L[j][0]) Ljk = U.find(L[j][k]) if numlst[Lj0] != numlst[Ljk]: if numlst[Lj0] != -1 and numlst[Ljk] != -1: flag = 0 else: mx = max(numlst[Lj0], numlst[Ljk]) U.union(Lj0, Ljk) numlst[U.find(Lj0)] = mx else: if numlst[Lj0] != -1: cnt -= 1 mx = max(numlst[Lj0], numlst[Ljk]) U.union(Lj0, Ljk) numlst[U.find(Lj0)] = mx ans *= pow(10, cnt * (mod - 2), mod) ans %= mod if flag: print(ans) else: print(0)