#include <bits/stdc++.h>
using namespace std;
long long int m = 998244353;
int base = 2002;
long long int dp[2][4025], a[2005];
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, k;
  cin >> n >> k;
  k %= m;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  if (a[0] == a[1 % n]) {
    dp[0][base] = k;
  } else {
    dp[0][base + 1] = 1;
    dp[0][base - 1] = 1;
    dp[0][base] = k - 2;
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= 4005; j++) {
      if (a[i] == a[(i + 1) % n]) {
        dp[1][j] = (dp[1][j] + k * dp[0][j]) % m;
      } else {
        dp[1][j] = (dp[1][j] + (k - 2) * dp[0][j]) % m;
        dp[1][j - 1] = (dp[1][j - 1] + dp[0][j]) % m;
        dp[1][j + 1] = (dp[1][j + 1] + dp[0][j]) % m;
      }
    }
    for (int j = 1; j <= 4005; j++) dp[0][j] = dp[1][j], dp[1][j] = 0;
  }
  long long int ans = 0;
  for (int i = base + 1; i <= 4005; i++) ans = (ans + dp[0][i]) % m;
  cout << (ans + m) % m;
  return 0;
}
