#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long maxn = 1e4 + 888;
long long saveori[maxn];
long long f[maxn];
long long ni[maxn];
long long kf[maxn];
long long k2f[maxn];
inline long long C(long long a, long long b) {
  return f[a] * ni[b] % mod * ni[a - b] % mod;
}
inline long long qpow(long long a, long long n) {
  long long res = 1;
  long long base = a;
  while (n) {
    if (n & 1) res = res * base % mod;
    base = base * base % mod;
    n >>= 1;
  }
  return res;
}
long long n, k;
void init() {
  f[0] = 1;
  for (long long i = 1; i < 2222; i++) f[i] = f[i - 1] * i % mod;
  for (long long i = 0; i < 2222; i++) ni[i] = qpow(f[i], mod - 2);
  kf[0] = 1;
  for (long long i = 1; i < 2222; i++) kf[i] = kf[i - 1] * k % mod;
  k2f[0] = 1;
  for (long long i = 1; i < 2222; i++) k2f[i] = k2f[i - 1] * (k - 2) % mod;
}
void solve() {
  scanf("%lld %lld", &n, &k);
  init();
  for (long long i = 0; i < n; i++) scanf("%lld", &saveori[i]);
  long long N = 0;
  for (long long i = 0; i < n; i++)
    if (saveori[i] != saveori[(i + 1) % n]) N++;
  long long ans = 0;
  for (long long A = 1; A <= N; A++) {
    for (long long B = 0; B < A && A + B <= N; B++) {
      long long tempans =
          C(N, A) * C(N - A, B) % mod * k2f[N - A - B] % mod * kf[n - N] % mod;
      ans += tempans;
      ans %= mod;
    }
  }
  printf("%lld\n", ans);
}
signed main() { solve(); }
