#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
const long long MOD = 998244353;
long long n, k;
long long a[N];
long long cache[N][N + N];
long long dp(long long i, long long diff) {
  if (i >= n) return (diff > 0);
  long long &ans = cache[i][diff + N];
  if (ans != -1) return ans;
  if (a[i] == a[(i + 1) % n])
    ans = (k * dp(i + 1, diff)) % MOD;
  else {
    ans = dp(i + 1, diff - 1) + dp(i + 1, diff + 1);
    ans += (k - 2) * dp(i + 1, diff);
    ans %= MOD;
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(cache, -1, sizeof(cache));
  cin >> n >> k;
  if (n == 1 || k == 1) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = dp(0, 0);
  cout << ans;
  return 0;
}
