#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long a[2005], b[2005], c[2005];
long long fun(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}
long long fu(long long n, long long m) {
  if (m > n || m < 0) return 0;
  if (m == 0 || m == n) return 1;
  return b[n] * c[m] % mod * c[n - m] % mod;
}
int main() {
  b[0] = 1;
  for (int i = 1; i <= 2000; i++) {
    b[i] = b[i - 1] * i % mod;
    c[i] = fun(b[i], mod - 2);
  }
  long long n, k, num = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  a[0] = a[n];
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] != a[i]) num++;
  }
  long long sum = 0;
  for (long long i = 0; i <= num / 2; i++)
    sum = (sum + fu(num, i) * fu(num - i, i) % mod * fun(k - 2, num - 2 * i) %
                     mod * fun(k, n - num)) %
          mod;
  sum = (fun(k, n) - sum + mod) * fun(2, mod - 2) % mod;
  printf("%lld\n", sum);
}
