#include <bits/stdc++.h>
using namespace std;
int h[2050];
long long dp[2050][5050];
int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  h[0] = h[n];
  dp[0][n - 1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 2 * n; j++) {
      if (h[i] == h[i - 1])
        dp[i][j] = dp[i - 1][j] * k;
      else {
        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * (k - 2) + dp[i - 1][j + 1];
      }
      dp[i][j] %= mod;
    }
  }
  long long ans = 0;
  for (int i = n; i <= 2 * n; i++) {
    ans += dp[n][i];
    ans %= mod;
  }
  cout << ans;
  return 0;
}
