#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }
  if (k == 1) {
    cout << "0\n";
    return 0;
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(2 * n + 1, 0));
  dp[0][n] = 1;
  for (int i = 1; i <= n; i++) {
    for (int bal = 0; bal < dp[0].size(); bal++) {
      if (ans[i - 1] == ans[i % ans.size()]) {
        dp[i][bal] = k * dp[i - 1][bal] % 998244353;
      } else {
        dp[i][bal] = dp[i - 1][bal] * (k - 2) % 998244353;
        if (bal > 0) {
          dp[i][bal] += dp[i - 1][bal - 1];
          dp[i][bal] %= 998244353;
        }
        if (bal < dp[0].size() - 1) {
          dp[i][bal] += dp[i - 1][bal + 1];
          dp[i][bal] %= 998244353;
        }
      }
    }
  }
  int64_t out = 0;
  for (int i = n + 1; i < dp[0].size(); i++) {
    out += dp.back()[i];
    out %= 998244353;
  }
  cout << out << '\n';
  return 0;
}
