#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int N = 3e3;
long long dmod(long long x) { return x % MOD; }
int n, k;
int h[N + 5];
long long memo[N + 5][2 * N + 5];
long long dp(int idx, int gap) {
  if (idx > n) {
    if (gap > 0) return 1;
    return 0;
  }
  long long &ret = memo[idx][gap + N];
  if (ret != -1) return ret;
  ret = 0ll;
  if (h[idx] == h[idx % n + 1]) {
    ret = dmod((long long)k * dp(idx + 1, gap));
  } else {
    ret = dp(idx + 1, gap + 1);
    ret = dmod(ret + dp(idx + 1, gap - 1));
    ret = dmod(ret + dmod((long long)(k - 2) * dp(idx + 1, gap)));
  }
  return ret;
}
int main() {
  memset(memo, -1, sizeof(memo));
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  printf("%lld\n", dp(1, 0));
  return 0;
}
