class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a0: result2.append(result[i]) return result2 mod=998244353 H,W=map(int,input().split()) A=[list(map(int,input().split())) for i in range(H)] D=dsu(H+W) P=pow(2,H+W-1,mod) Q=pow(2,mod-2,mod) S=[] for i in range(H): for j in range(W): S.append(A[i][j]*H*W+i*W+j) S.append(0) S.sort(reverse=True) for i in range(H*W+1): S[i]=(S[i]//(H*W),(S[i]//W)%H,S[i]%W) ANS=(P-1)*S[0][0]%mod for i in range(H*W): x,y=S[i][1],S[i][2] z=S[i][0]-S[i+1][0] if D.merge(x,H+y): P=P*Q%mod if P==1: break ANS=(ANS-(P-1)*z)%mod print(ANS%mod)