#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 2e3 + 5;
const long long MOD = 998244353;
int n, a[N], b[N], c[N], tab[N], k;
long long dp[N][2 * N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &tab[i]);
  if (tab[n] == tab[1])
    a[n] = k;
  else {
    a[n] = k - 2;
    b[n] = 1;
    c[n] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (tab[i] == tab[i + 1])
      a[i] = k;
    else {
      a[i] = k - 2;
      b[i] = 1;
      c[i] = 1;
    }
  }
  dp[0][N] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 2 * N - 1; j++) {
      dp[i][j] = (long long)a[i] * dp[i - 1][j];
      if (j != 0) dp[i][j] += (long long)b[i] * dp[i - 1][j - 1];
      dp[i][j] += (long long)c[i] * dp[i - 1][j + 1];
      dp[i][j] %= MOD;
    }
  long long ans = 0;
  for (int i = N + 1; i < 2 * N - 1; i++) ans += dp[n][i];
  ans %= MOD;
  printf("%lld", ans);
  return 0;
}
