#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int h[N], fact[N], factRev[N];
int sum(int a, int b) { return ((1LL * a + b) % mod + mod) % mod; }
int mul(int a, int b) { return ((1LL * a * b) % mod + mod) % mod; }
int pw(int a, int b) {
  int res = 1, tmp = a;
  while (b) {
    if (b & 1) res = mul(res, tmp);
    tmp = mul(tmp, tmp);
    b >>= 1;
  }
  return res;
}
int divid(int a, int b) { return mul(a, pw(b, mod - 2)); }
void prepros() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
  factRev[N - 1] = divid(1, fact[N - 1]);
  for (int i = N - 2; ~i; i--) factRev[i] = mul(factRev[i + 1], i + 1);
}
int c(int a, int b) { return mul(fact[a], mul(factRev[b], factRev[a - b])); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];
  if (k == 1) return cout << "0\n", 0;
  prepros();
  vector<int> v;
  v.push_back(h[0]);
  for (int i = 1; i < n; i++)
    if (h[i] != h[i - 1]) v.push_back(h[i]);
  if (v.back() == h[0]) v.pop_back();
  int ans = pw(k, v.size());
  for (int i = 0; 2 * i <= v.size(); i++)
    ans = sum(ans, -mul(mul(c(v.size(), i), c(v.size() - i, i)),
                        pw(k - 2, v.size() - 2 * i)));
  ans = divid(ans, 2);
  ans = mul(ans, pw(k, n - v.size()));
  cout << ans << "\n";
  return 0;
}
