#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7, p = 998244353;
long long n, m, w[N], fac[N], ifac[N];
inline long long pows(long long u, int v) {
  long long ans = 1;
  while (v > 0) {
    if (v & 1) ans = ans * u % p;
    u = u * u % p, v = v >> 1;
  }
  return ans;
}
inline long long getans(int a, int b) {
  if (a < b) return 0;
  return fac[a] * ifac[b] % p * ifac[a - b] % p;
}
int main() {
  cin >> n >> m;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= 1e6; i++)
    fac[i] = fac[i - 1] * i % p, ifac[i] = pows(fac[i], p - 2);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  w[n + 1] = w[1];
  int s = 0;
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    if (w[i] != w[i + 1]) s++;
  for (int i = 0; i <= s; i++) {
    int x = s - i;
    long long cs = 0;
    if (x % 2 == 1)
      cs = pows(2, x - 1);
    else
      cs = ((pows(2, x) - getans(x, x / 2)) * (p + 1) / 2) % p;
    cs = (cs + p) % p;
    sum = (sum + cs * getans(s, i) % p * pows(m - 2, i)) % p;
  }
  cout << sum * pows(m, n - s) % p << endl;
  return 0;
}
