#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
  } else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const long long mod = 998244353;
const long long N = 2005;
long long n, k, ans, a[N], b[N], f[N][N << 1];
signed main() {
  read(n);
  read(k);
  for (long long i = 1; i <= n; i++) read(a[i]), b[i % n + 1] = a[i];
  if (k == 1) {
    write(0);
    return 0;
  }
  f[0][0 + n] = 1;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      for (long long j = -n; j <= n; j++)
        f[i][j + n] = f[i - 1][j + n] * k % mod;
    } else {
      for (long long j = -n; j <= n; j++)
        f[i][j + n] = (f[i - 1][j - 1 + n] + f[i - 1][j + 1 + n] +
                       (k - 2) * f[i - 1][j + n]) %
                      mod;
    }
  }
  for (long long i = 1; i <= n; i++) (ans += f[n][i + n]) %= mod;
  write(ans);
}
