#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long N = 998244353, M = 31;
long long n, m, t, k, f, mi = 2e9, x, y, z, ma, x3, x2, y2, l, r, i, j, ans, vv,
                         a[410000], b[410000], d[410000], d2[410000],
                         dp[410000];
char c[410000];
string s;
vector<long long> v, v2, v3;
long long vozv(long long x, long long y) {
  if (y == 0) return 1ll;
  if (y == 1) return x;
  long long t = vozv(x, y / 2);
  t = (t * t) % N;
  if (y % 2 == 0)
    return (t) % N;
  else
    return (t * x) % N;
}
long long F(long long x, long long y, long long z) {
  return (dp[x] * vozv((z * dp[y] * dp[x - y]) % N, N - 2)) % N;
}
int main() {
  cin >> n >> m;
  k = -1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != a[i - 1]) k++;
  }
  if (a[1] == a[n]) k--;
  k++;
  ans = 1;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (i = 1; i <= n - k; i++) ans = (ans * m) % N;
  b[0] = 1;
  for (i = 1; i <= k; i++) b[i] = (b[i - 1] * (m - 2)) % N;
  d[0] = 1;
  for (i = 1; i <= k; i++) d[i] = (d[i - 1] * 2ll) % N;
  dp[0] = 1;
  for (i = 1; i <= k; i++) dp[i] = (dp[i - 1] * i) % N;
  t = 0;
  for (z = 0; z < k; z++) {
    l = d[(k - z - 1)];
    if ((k - z) % 2 == 0) l = (l - F(k - z, (k - z) / 2, 2ll) + N) % N;
    t = (t + b[z] * l % N * F(k, z, 1ll)) % N;
  }
  ans = (ans * t) % N;
  cout << ans;
}
