#include <bits/stdc++.h>
using namespace std;
const int MAX = (2e3) + 5, MOD = 998244353;
long long n, k, ara[MAX], dp[MAX][MAX * 2];
long long rec(int p, int sum) {
  if (p == n + 1) {
    return (sum > 2000);
  }
  long long &temp = dp[p][sum];
  if (temp != -1) {
    return temp;
  }
  int me = ara[p], nex = ara[(p % n) + 1];
  if (me == nex || k == 1) {
    temp = rec(p + 1, sum) * k;
  } else {
    temp =
        rec(p + 1, sum - 1) + rec(p + 1, sum + 1) + rec(p + 1, sum) * (k - 2);
  }
  return temp = (temp % MOD);
}
int main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  cout << rec(1, 2000) << endl;
  return 0;
}
