#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int MOD = 998244353;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
long long dp[2][4010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n + 1);
  for (int i = (int)(1); i < (int)(n + 1); i++) cin >> a[i];
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  int z = 2005;
  dp[0][z] = 1LL;
  for (int i = (int)(1); i < (int)(n + 1); i++) {
    int cr = i & 1, pr = 1 - cr;
    int nw = a[i], ol = (i == 1 ? a[n] : a[i - 1]);
    for (int j = (int)(1); j < (int)(4009); j++) {
      if (nw == ol)
        (dp[cr][j] += (dp[pr][j] * k) % MOD) %= MOD;
      else {
        (dp[cr][j + 1] += dp[pr][j]) %= MOD;
        (dp[cr][j - 1] += dp[pr][j]) %= MOD;
        (dp[cr][j] += (dp[pr][j] * (k - 2)) % MOD) %= MOD;
      }
    }
    for (int j = 0; j < (int)(4010); j++) dp[pr][j] = 0LL;
  }
  long long ans = 0LL;
  for (int i = (int)(1); i < (int)(2005); i++) (ans += dp[n & 1][z + i]) %= MOD;
  cout << ans << endl;
  return 0;
}
