#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
const long long mod = 998244353;
long long f[2010][4020];
int h[N];
int main() {
  ios::sync_with_stdio(false);
  int n;
  long long k;
  cin >> n >> k;
  int i;
  for (i = 1; i <= n; i++) cin >> h[i];
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  memset(f, 0, sizeof f);
  f[0][2001] = 1;
  for (i = 1; i <= n; i++) {
    for (int j = 1; j <= 4001; j++) {
      if (h[i] == h[i % n + 1]) {
        f[i][j] = f[i - 1][j] * k % mod;
      } else {
        f[i][j] =
            (f[i - 1][j - 1] + f[i - 1][j + 1] + f[i - 1][j] * (k - 2)) % mod;
      }
    }
  }
  long long ans = 0;
  for (i = 2002; i <= 2001 + n; i++) {
    ans = (ans + f[n][i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
