#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4005;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
long long n, k, h[MAXN];
long long dp[2005][4005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> h[i];
  dp[0][2001] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4001; j++) {
      if (h[i] == h[i % n + 1])
        dp[i][j] = dp[i - 1][j] * k % mod;
      else
        dp[i][j] =
            (dp[i - 1][j + 1] + dp[i - 1][j - 1] + dp[i - 1][j] * (k - 2)) %
            mod;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + dp[n][2001 + i]) % mod;
  cout << ans << endl;
  return 0;
}
