#include using namespace std; struct UnionFind { vector par; vector size; UnionFind(int n) { par.resize(n); size.resize(n,1); for(int i = 0; i < n; i++) { par[i] = i; } } int find(int x) { if(par[x] == x) { return x; } return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int consize(int x) { return size[find(x)]; } bool unite(int x, int y) { x = find(x); y = find(y); if(x == y) { return false; } if(size[x] > size[y]) { swap(x,y); } par[x] = y; size[y] += size[x]; return true; } }; constexpr int mod = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int W,H; cin >> W >> H; vectortmp(W,-1); UnionFind uf(W); bool f = true; for(int i = 0; i < H; i++) { string Q; cin >> Q; vector>id(26); for(int j = 0; j < W; j++) { if(Q[j] == '?') continue; if(Q[j] >= '0' && Q[j] <= '9') { int c = Q[j]-'0'; if(tmp[j] == -1) tmp[j] = c; else if(tmp[j] != c) f = false; } else { id[Q[j]-'a'].push_back(j); } } for(int j = 0; j < 26; j++) { for(int k = 1; k < id[j].size(); k++) { uf.unite(id[j][k-1],id[j][k]); } } mapmp; for(int j = 0; j < W; j++) { int c = uf.find(j); int d = tmp[j]; if(!mp.count(c)) { mp[c] = d; } else { if(mp[c] == -1) { mp[c] = d; } else if(d != -1 && mp[c] != d) { f = false; } } } if(!f) { cout << 0 << "\n"; continue; } int ans = 1; for(auto j:mp) { if(j.second == -1) { ans = 10ll*ans%mod; } } cout << ans << "\n"; } }