import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.par = [-1] * N def find(self, x): r = x while self.par[r] >= 0: r = self.par[r] while x != r: tmp = self.par[x] self.par[x] = r x = tmp return r def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] mod = 998244353 H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] vals = [] for i in range(H): for j in range(W): vals.append((A[i][j], i, j)) vals.sort(key=lambda p: -p[0]) uf = UnionFind(H+W) comp = H + W ans = 0 for x, i, j in vals: if uf.same(i, H+j): continue ans = (ans + x * pow(2, comp - 1, mod)) % mod uf.unite(i, H+j) comp -= 1 print(ans * pow(2, mod-2, mod) % mod)