#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const long long mod = 998244353;
const int maxn = 1e4;
long long fac[maxn], ifac[maxn], inv[maxn];
long long nck(long long n, long long k) {
  if (n < k) return 0;
  return fac[n] * ifac[k] % mod * ifac[n - k] % mod;
}
void gen_inv() {
  fac[0] = inv[0] = ifac[0] = 1;
  fac[1] = inv[1] = ifac[1] = 1;
  for (int i = 2; i < maxn; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
    ifac[i] = ifac[i - 1] * inv[i] % mod;
  }
  assert(nck(4, 2) == 6);
}
long long pw(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) res = res * x % mod;
    x = x * x % mod;
    y = y / 2;
  }
  return ((res % mod) + mod) % mod;
}
long long n, k;
long long a[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  gen_inv();
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  long long t = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i + 1]) t++;
  }
  long long res = 0;
  for (long long z = 0; z <= n - t; z++) {
    long long sum = 0;
    for (long long y = 0; y <= n - t - z; y++) {
      long long x = n - t - z - y;
      if (y > x) {
        sum += nck(n - t - z, y);
        sum %= mod;
      }
    }
    long long cur = sum * pw(k - 2, z) % mod * nck(n - t, z) % mod;
    res += cur;
    res %= mod;
  }
  res = res * pw(k, t) % mod;
  cout << res << endl;
  return 0;
}
