#include <bits/stdc++.h>
using namespace std;
const long long P = 998244353;
long long solve(long long k, long long n) {
  vector<long long> dp(2 * n + 1), dp1(2 * n + 1);
  dp[n] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 2 * n + 1; j++) {
      dp1[j] = (k - 2) * dp[j];
      if (j > 0) dp1[j] += dp[j - 1];
      if (j < 2 * n) dp1[j] += dp[j + 1];
      dp1[j] %= P;
    }
    dp = dp1;
  }
  long long ans = 0;
  for (long long j = n + 1; j < 2 * n + 1; j++) ans = (ans + dp[j]) % P;
  return ans;
}
signed main() {
  iostream::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (long long &h1 : h) cin >> h1;
  long long mul = 1, n1 = 0;
  for (long long i = 0; i < h.size(); i++)
    if (h[i] == h[(i + 1) % n])
      mul = mul * k % P;
    else
      n1++;
  cout << mul * solve(k, n1) % P << endl;
}
