#include <bits/stdc++.h>
using namespace std;
char _buf[100000], *_p1 = _buf, *_p2 = _buf;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return (f == 1) ? x : -x;
}
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
const int maxn = 2e5 + 5, zero = 2e5 + 1, mod = 998244353;
long long dp[2][maxn * 2];
int a[maxn], b[maxn], n, k, now, last;
inline void init() {}
inline void input() {
  n = gi(), k = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi();
  a[n + 1] = a[1];
}
inline void solve() {
  now = 1, last = 0;
  dp[now][zero] = 1;
  for (int i = 1; i <= n; ++i) {
    now = now ^ 1, last = now ^ 1;
    memset(dp[now], 0, sizeof(dp[now]));
    for (int j = zero - i; j <= zero + i; ++j) {
      if (a[i] != a[i + 1]) {
        dp[now][j + 1] = (dp[now][j + 1] + dp[last][j]) % mod;
        dp[now][j] = (dp[now][j] + (k - 2) * dp[last][j]) % mod;
        dp[now][j - 1] = (dp[now][j - 1] + dp[last][j]) % mod;
      } else {
        dp[now][j] = (dp[now][j] + k * dp[last][j]) % mod;
      }
    }
  }
  long long ans = 0;
  for (int j = zero + 1; j <= zero + n; ++j) ans = (ans + dp[now][j]) % mod;
  printf("%lld\n", ans);
}
int main() {
  init();
  input();
  solve();
  return 0;
}
