#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = 998244353;
int n, k, diff, a[N];
long long f[N], inv[N], P[N], ans;
long long fpow(long long base, long long expo) {
  long long ans = 1LL;
  while (expo) {
    if (expo & 1LL) ans = (ans * base) % M;
    base = (base * base) % M;
    expo >>= 1LL;
  }
  return ans;
}
long long A(long long N, long long K) {
  long long ans = f[N];
  ans *= fpow(f[N - K], M - 2);
  ans %= M;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) diff += a[i] != a[(i - 1 + n) % n];
  f[0] = 1LL;
  inv[0] = fpow(1LL, M - 2LL);
  for (int i = 1; i <= n; ++i) {
    f[i] = (f[i - 1] * i * 1LL) % M;
    inv[i] = fpow(f[i], M - 2LL) % M;
  }
  for (int i = 0; i <= diff; ++i) P[i] = A(diff, i);
  for (int minus = 1; minus <= diff; ++minus) {
    for (int plus = 0; plus <= min(minus - 1, diff - minus); ++plus) {
      long long t = P[minus + plus] * inv[minus];
      t %= M;
      t *= inv[plus];
      t %= M;
      t *= fpow(k - 2LL, diff - minus - plus);
      t %= M;
      ans = (ans + t) % M;
    }
  }
  ans = (ans * fpow(k, n - diff)) % M;
  cout << ans;
}
