#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 998244353;
const int G = 3;
const int Gi = (mods + 1) / 3;
const int MAXN = 1e6 + 50;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int f[MAXN], rev[MAXN], a[MAXN], Limit, l;
inline int upd(int x, int y) { return x + y >= mods ? x + y - mods : x + y; }
inline int quick_pow(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1ll * ret * x % mods;
    x = 1ll * x * x % mods;
  }
  return ret;
}
inline void Number_Theoretic_Transform(int *A, int opt) {
  for (int i = 0; i < Limit; i++)
    if (rev[i] < i) swap(A[rev[i]], A[i]);
  for (int mid = 1; mid < Limit; mid <<= 1) {
    int Wn = quick_pow(opt == 1 ? G : Gi, (mods - 1) / (mid << 1));
    for (int j = 0; j < Limit; j += (mid << 1))
      for (int k = j, w = 1; k < j + mid; k++, w = 1ll * w * Wn % mods) {
        int x = A[k], y = 1ll * A[k + mid] * w % mods;
        A[k] = upd(x, y), A[k + mid] = upd(x, mods - y);
      }
  }
  if (opt == -1) {
    int invLimit = quick_pow(Limit, mods - 2);
    for (int i = 0; i < Limit; i++) A[i] = 1ll * A[i] * invLimit % mods;
  }
}
int main() {
  int n = read(), k = read(), num = 0, ans = 0;
  if (n <= 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1, j = 2; i <= n; i++, j = j % n + 1)
    if (a[i] != a[j]) num++;
  f[1] = k - 2, f[0] = f[2] = 1;
  Limit = 1, l = 0;
  while (Limit <= num * 2) Limit <<= 1, l++;
  for (int i = 1; i < Limit; i++)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (l - 1));
  Number_Theoretic_Transform(f, 1);
  for (int i = 0; i < Limit; i++) f[i] = quick_pow(f[i], num);
  Number_Theoretic_Transform(f, -1);
  for (int i = num + 1; i <= num * 2; i++) ans = upd(ans, f[i]);
  printf("%d\n", 1ll * ans * quick_pow(k, n - num) % mods);
  return 0;
}
