#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[2020];
long long dp[2020][2020 * 2];
int main() {
  scanf(" %lld%lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  a[n] = a[0];
  memset(dp, 0, sizeof(dp));
  if (a[0] == a[1]) {
    dp[0][2020] = k % 998244353;
  } else {
    dp[0][2020] = (k - 2) % 998244353;
    dp[0][2020 - 1] = 1;
    dp[0][2020 + 1] = 1;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 2020 - n; j <= 2020 + n; j++) {
      if (a[i] == a[i + 1]) {
        dp[i][j] = (dp[i - 1][j] * k) % 998244353;
      } else {
        dp[i][j] += dp[i - 1][j] * (k - 2);
        dp[i][j] += dp[i - 1][j - 1];
        dp[i][j] += dp[i - 1][j + 1];
        dp[i][j] %= 998244353;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[n - 1][i + 2020];
  ans %= 998244353;
  printf("%lld\n", ans);
}
