#include <bits/stdc++.h>
using namespace std;
const int M = 4e3 + 10, mod = 998244353;
int dp[2][M], base = 2005;
int mul(int x, int y) { return 1ll * x * y % mod; }
void inc(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int a[M];
int main() {
  int n, K;
  scanf("%d%d", &n, &K);
  dp[0][base] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int now = i & 1, pre = 1 - now;
    for (int j = base - n; j <= base + n; j++) dp[now][j] = 0;
    int x = a[i], y = (i == n) ? a[1] : a[i + 1];
    if (x == y) {
      for (int j = base - n; j <= base + n; j++)
        dp[now][j] = mul(K, dp[pre][j]);
      continue;
    }
    int add = 0, way = K - 2;
    for (int j = base - n; j <= base + n; j++)
      inc(dp[now][j], mul(dp[pre][j], way));
    add = 1, way = 1;
    for (int j = base - n + add; j <= base + n; j++)
      inc(dp[now][j], mul(dp[pre][j - add], way));
    add = -1, way = 1;
    for (int j = base - n; j <= base + n + add; j++)
      inc(dp[now][j], mul(dp[pre][j - add], way));
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    inc(ans, dp[n & 1][base + i]);
  }
  printf("%d\n", ans);
}
