#include <bits/stdc++.h>
using namespace std;
const int maxN = 201000;
const long long mod = 998244353;
long long powmod(long long a, long long x) {
  long long res = 1;
  while (x) {
    if (x & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    x >>= 1;
  }
  return res;
}
long long modinv(long long x) { return powmod(x, mod - 2); }
long long f[maxN];
long long finv[maxN];
vector<int> cur, a;
int cnt(vector<int>& a, vector<int>& b, int shift) {
  int n = a.size();
  int res = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == b[(i + shift) % n]) {
      ++res;
    }
  }
  return res;
}
int cres = 0;
int cres2 = 0;
void gen(int idx, int n, int k) {
  if (idx == n) {
    if (cnt(cur, a, 0) < cnt(cur, a, 1)) {
      ++cres;
    } else {
      ++cres2;
    }
    return;
  }
  for (int i = 0; i < k; ++i) {
    cur.push_back(i);
    gen(idx + 1, n, k);
    cur.pop_back();
  }
}
long long cnk(int n, int k) {
  return ((f[n] * finv[k]) % mod * finv[n - k]) % mod;
}
void solve() {
  int n, k;
  cin >> n >> k;
  a = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  if (k == 1) {
    cout << 0 << endl;
    return;
  }
  int have = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] != a[(i + 1) % n]) {
      ++have;
    }
  }
  f[0] = 1;
  for (int i = 1; i < maxN; ++i) {
    f[i] = f[i - 1] * i;
    f[i] %= mod;
  }
  for (int i = 0; i < maxN; ++i) {
    finv[i] = modinv(f[i]);
  }
  long long res = 1;
  res *= powmod(k, n - have);
  res %= mod;
  long long sum = 0;
  for (int i = 0; i < have; ++i) {
    long long cur = 1;
    cur *= powmod(k - 2, i);
    cur *= cnk(have, i);
    cur %= mod;
    long long val = 0;
    if ((have - i) % 2 == 0) {
      val = powmod(2, have - i);
      val -= cnk(have - i, (have - i) / 2);
      val *= modinv(2);
      val %= mod;
      val += mod;
      val %= mod;
    } else {
      val = powmod(2, have - i - 1);
    }
    cur *= val;
    cur %= mod;
    sum += cur;
    sum %= mod;
  }
  res *= sum;
  res %= mod;
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  t = 1;
  for (int tt = 0; tt < t; ++tt) {
    solve();
  }
  return 0;
}
