#include <bits/stdc++.h>
using namespace std;
int n, k, v[2002];
long long dp[3][4002];
const int mod = 998244353;
int nxt(int poz) {
  if (poz == n) return 1;
  return poz + 1;
}
int main() {
  if (1) ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  if (n == 1) {
    cout << 0;
    return 0;
  }
  if (v[1] == v[2])
    dp[1][2000] = k;
  else {
    dp[1][2000] = k - 2;
    dp[1][2001] = 1;
    dp[1][1999] = 1;
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= 4000; ++j) {
      if (v[i] == v[nxt(i)]) {
        dp[2][j] = (dp[2][j] + dp[1][j] * k) % mod;
      } else {
        dp[2][j + 1] = (dp[2][j + 1] + dp[1][j]);
        if (dp[2][j + 1] >= mod) dp[2][j + 1] -= mod;
        dp[2][j] = (dp[2][j] + dp[1][j] * (k - 2)) % mod;
        dp[2][j - 1] = (dp[2][j - 1] + dp[1][j]);
        if (dp[2][j - 1] >= mod) dp[2][j - 1] -= mod;
      }
    }
    memcpy(dp[1], dp[2], sizeof(dp[2]));
    memset(dp[2], 0, sizeof(dp[2]));
  }
  long long ans = 0;
  for (int i = 2001; i <= 4001; ++i) ans = (ans + dp[1][i]) % mod;
  cout << ans;
  return 0;
}
