#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = 998244353;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, k;
int a[3][2020];
int d[3] = {-1, 0, 1};
int h[2020];
int dp[2020][4040];
bool was[2020][4040];
int calc(int ind, int balance) {
  if (ind == n) {
    if (balance > 0) return 1;
    return 0;
  }
  int &res = dp[ind][balance + n];
  if (was[ind][balance]) return res;
  res = 0;
  was[ind][balance] = 1;
  for (int i = 0; i < 3; i++) {
    int cur = a[i][ind] * 1ll * calc(ind + 1, balance + d[i]) % mod;
    cur += mod;
    cur %= mod;
    res += cur;
    res %= mod;
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", h + i);
  for (int i = 0; i < n; i++) {
    int x = h[i];
    int y = h[(i + 1) % n];
    if (x == y) {
      a[0][i] = a[2][i] = 0;
      a[1][i] = k;
    } else {
      a[0][i] = 1;
      a[2][i] = 1;
      a[1][i] = k - 2;
    }
  }
  cout << calc(0, 0) << endl;
  return 0;
}
