#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e3, M = 998244353;
int n, h[mxN], k;
long long dp[mxN + 1][2 * mxN + 1];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  dp[0][n] = 1;
  for (int i = 0; i < n; ++i) cin >> h[i];
  for (int i = 0; i < n; ++i) {
    int c0, c1, c2;
    if (h[i] == h[(i + 1) % n]) {
      c0 = c2 = 0;
      c1 = k;
    } else {
      c0 = c2 = 1;
      c1 = k - 2;
    }
    for (int j = 1; j < 2 * n; ++j) {
      dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * c0) % M;
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * c1) % M;
      dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * c2) % M;
    }
  }
  long long ans = 0;
  for (int i = n + 1; i <= 2 * n; ++i) ans += dp[n][i];
  cout << ans % M;
}
