#include <bits/stdc++.h>
using namespace std;
const int MAX = 2010;
const int MOD = 998244353;
inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }
int ara[MAX];
int dp[MAX][4030];
int n, k;
int call(int pos, int diff) {
  if (pos > n) return (diff > 2002);
  if (dp[pos][diff] != -1) return dp[pos][diff];
  int ret = 0;
  int nw, nd;
  nw = ara[pos];
  nd = diff;
  if (nw == ara[pos + 1]) nd++;
  if (nw == ara[pos]) nd--;
  ret = add(ret, call(pos + 1, nd));
  if (ara[pos] != ara[pos + 1]) {
    nw = ara[pos + 1];
    nd = diff;
    if (nw == ara[pos + 1]) nd++;
    if (nw == ara[pos]) nd--;
    ret = add(ret, call(pos + 1, nd));
  }
  int way;
  if (ara[pos] == ara[pos + 1])
    way = max(0, k - 1);
  else
    way = max(0, k - 2);
  ret = add(ret, mul(way, call(pos + 1, diff)));
  return dp[pos][diff] = ret;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  ara[n + 1] = ara[1];
  memset(dp, -1, sizeof(dp));
  cout << call(1, 2002) << endl;
  return 0;
}
