#include <bits/stdc++.h>
using namespace std;
const long long N = 2004, mod = 998244353;
long long n, k, a[N], c[N][N], K[N];
long long x = 1, cnt, ans;
int main() {
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i && a[i] == a[i - 1]) x *= k, x %= mod, cnt++;
  }
  K[0] = 1;
  for (long long i = 1; i <= n; i++) K[i] = (K[i - 1] * (k - 2)) % mod;
  if (a[0] == a[n - 1]) x *= k, cnt++, x %= mod;
  n -= cnt;
  for (long long i = 0; i < N; i++) {
    c[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      c[i][j] %= mod;
    }
  }
  ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long cur = 1;
    for (long long j = 0; j + i <= n && j < i; j++) {
      cur *= (c[n][i]);
      cur %= mod;
      cur *= (c[n - i][n - i - j]);
      cur %= mod;
      cur *= (K[n - i - j]);
      cur %= mod;
      ans += cur;
      ans %= mod;
      cur = 1;
    }
  }
  ans *= x;
  ans %= mod;
  cout << ans;
  return 0;
}
