#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353, inv2 = (MOD + 1) / 2;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long long dp[2010][4100];
int a[200000 + 10], b[200000 + 10];
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
int main() {
  int n = read(), k = read();
  for (int i = (int)1; i <= (int)n; i++) a[i] = read();
  for (int i = (int)1; i <= (int)n; i++) b[i % n + 1] = a[i];
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  int eps = n;
  dp[0][0 + eps] = 1;
  for (int i = (int)1; i <= (int)n; i++) {
    if (a[i] == b[i]) {
      for (int j = (int)-n; j <= (int)n; j++)
        dp[i][j + eps] = dp[i - 1][j + eps] * k % MOD;
      continue;
    }
    for (int j = (int)-n; j <= (int)n; j++)
      dp[i][j + eps] = (dp[i - 1][j - 1 + eps] + dp[i - 1][j + 1 + eps] +
                        1ll * (k - 2) * dp[i - 1][j + eps] % MOD) %
                       MOD;
  }
  long long ans = 0;
  for (int i = (int)1; i <= (int)n; i++) ans = (ans + dp[n][i + eps]) % MOD;
  printf("%I64d\n", ans);
  return 0;
}
