#include <bits/stdc++.h>
using namespace std;
long long n, k, dp[2002][4004], s[2002];
long long go(long long pos, long long del) {
  if (pos == 1) {
    if (del == 0) return k - 2 * (s[1] != s[n]);
    if (s[1] == s[n]) return 0;
    if (del == 1) return 1;
    if (del == -1) return 1;
    return 0;
  }
  long long &ans = dp[pos][del + 2002];
  if (ans != -1) return ans;
  ans = 0;
  if (s[pos] == s[pos - 1])
    ans = (ans + k * go(pos - 1, del)) % 998244353;
  else
    ans = (ans + go(pos - 1, del - 1) + go(pos - 1, del + 1) +
           (k - 2) * go(pos - 1, del)) %
          998244353;
  return ans;
}
void solve() {
  cin >> n >> k;
  for (long long i = 1; i < n + 1; i++) cin >> s[i];
  memset(dp, -1, sizeof dp);
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) ans = (ans + go(n, i)) % 998244353;
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
