#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
long long power(long long x, long long t) {
  long long ret = 1;
  for (; t; t >>= 1, x = x * x % P) {
    if (t & 1) {
      ret = ret * x % P;
    }
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  long long ans = power(M, N) * N % P;
 /* cerr << "ans = " << ans << '\n';
  vector<vector<long long>> pw(5001, vector<long long> (5001));
  for (int i = 1; i <= 5000; ++i) {
    pw[i][0] = 1;
    for (int j = 1; j <= 5000; ++j) {
      pw[i][j] = pw[i][j - 1] * i % P;
    }
  }
  auto pre = pw;
  for (int i = 1; i <= 5000; ++i) {
    for (int j = 1; j <= 5000; ++j) {
      pre[i][j] += pre[i - 1][j];
      pre[i][j] %= P;
    }
  }*/
  for (int i = 1; i < N; ++i) {
    long long tmp = 0;
    for (int k = 1; k < M; ++k) {
      tmp += power(k, i - 1) * power(M, N - i - 1) % P; 
    }
    if (i == 1) {
      ans -= power(M, N - 2) * (N - 1) % P;
      ans += P;
      ans %= P;
    }
    tmp = tmp * (N - i) % P;
    ans -= tmp;
    ans += P;
    ans %= P;
  } /*
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (j == i + 1) {
        ans -= power(M, N - 2);
        ans += P;
        ans %= P;
      }
      long long tmp = 0;
      tmp += pre[M - 1][j - i - 1];
      tmp = tmp * pw[M][N - (j - i + 1)] % P;
      ans -= tmp;
      ans += P;
      ans %= P; 
      for (int k = 1; k < M; ++k) {
        ans -= power(k, j - i - 1) * power(M, N - (j - i + 1)) % P;
        ans += P;
        ans %= P;
      }
    }
  }*/
  cout << ans << '\n';
  return 0;
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;
    ll sum = 0, mi = INF, a;
    rep(i, h)rep(j, w) {
    	cin >> a;
    	sum += a;
    	mi= min(mi, a);
    }
    cout << sum - mi * h * w << endl;
    return 0;
}


