#include <bits/stdc++.h>
using namespace std;
int moder = 998244353;
int amount, options;
int correct_ans[4005];
int mark[4005][4005], res[4005][4005];
int cal(int pos, int more) {
  if (pos == amount + 1) return more > amount;
  if (mark[pos][more]) return res[pos][more];
  mark[pos][more] = 1;
  if (correct_ans[pos] == correct_ans[pos + 1])
    res[pos][more] = (long long)options * cal(pos + 1, more) % moder;
  else {
    res[pos][more] = (cal(pos + 1, more + 1) + cal(pos + 1, more - 1)) % moder;
    res[pos][more] =
        (res[pos][more] + (long long)(options - 2) * cal(pos + 1, more)) %
        moder;
  }
  return res[pos][more];
}
void solve() {
  correct_ans[amount + 1] = correct_ans[1];
  printf("%d", cal(1, amount));
}
int main() {
  scanf("%d %d", &amount, &options);
  for (int i = 1; i <= amount; i++) scanf("%d", &correct_ans[i]);
  solve();
}
