#include <bits/stdc++.h>
using namespace std;
const long long NUM = 1e6 + 5;
const long long mod = 998244353;
const long long INF = 1e18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long cnt[n][5];
  for (int i = 0; i < n; i++) {
    int v = a[i];
    int u = a[(i + 1) % n];
    if (v == u) {
      cnt[i][0] = k;
      cnt[i][1] = cnt[i][2] = 0;
    } else {
      cnt[i][0] = k - 2;
      cnt[i][1] = cnt[i][2] = 1;
    }
  }
  long long dp[n][2 * n + 1];
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 2 * n; j++) {
      dp[i][j] = 0;
      if (j)
        dp[i][j] =
            (dp[i][j] + cnt[i][1] * (i ? dp[i - 1][j - 1] : (j - 1) == n)) %
            mod;
      if (j + 1 <= 2 * n)
        dp[i][j] =
            (dp[i][j] + cnt[i][2] * (i ? dp[i - 1][j + 1] : (j + 1) == n)) %
            mod;
      dp[i][j] = (dp[i][j] + cnt[i][0] * (i ? dp[i - 1][j] : (j) == n)) % mod;
    }
  long long ans = 0;
  for (int i = n + 1; i <= 2 * n; i++) ans = (ans + dp[n - 1][i]) % mod;
  cout << ans;
  return 0;
}
