#include <bits/stdc++.h>
using namespace std;
int inline read() {
  int num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const int maxn = 2010, mod = 998244353;
int n, k, h[maxn], f[maxn][maxn * 2 + 1];
int main() {
  n = read();
  k = read();
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) h[i] = read();
  if (h[1] == h[2])
    f[1][maxn] = k;
  else
    f[1][maxn] = k - 2, f[1][maxn + 1] = 1, f[1][maxn - 1] = 1;
  for (int i = 2; i <= n; i++) {
    int to;
    if (i != n)
      to = i + 1;
    else
      to = 1;
    for (int j = 0; j <= maxn * 2; j++) {
      if (h[i] == h[to])
        f[i][j] = (f[i][j] + 1ll * f[i - 1][j] * k % mod) % mod;
      else {
        if (j != 0) f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;
        if (j != maxn * 2) f[i][j] = (f[i][j] + f[i - 1][j + 1]) % mod;
        f[i][j] = (f[i][j] + 1ll * f[i - 1][j] * (k - 2)) % mod;
      }
    }
  }
  int ans = 0;
  for (int i = maxn + 1; i <= 2 * maxn; i++) ans = (ans + f[n][i]) % mod;
  cout << ans;
  return 0;
}
