#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
const int lbt = 998244353;
int fast_pow(int a, int t) {
  int ans = 1;
  for (int i = 31; i >= 0; i--) {
    ans = (long long)ans * ans % lbt;
    if (t >> i & 1) ans = (long long)a * ans % lbt;
  }
  return ans;
}
int d, x, y;
void gcd(int a, int b) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
    return;
  }
  gcd(b, a % b);
  int t = x;
  x = y;
  y = t - a / b * y;
}
int cal_rev(int a) {
  gcd(a, lbt);
  if (x < 0) x += lbt;
  return x;
}
int rev[maxn], fac[maxn], rfac[maxn];
void init() {
  rev[1] = 1;
  for (int i = 2; i < maxn; i++)
    rev[i] = (long long)(lbt - lbt / i) * rev[lbt % i] % lbt;
  fac[0] = rfac[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fac[i] = (long long)i * fac[i - 1] % lbt;
    rfac[i] = (long long)rev[i] * rfac[i - 1] % lbt;
  }
}
struct poly {
  vector<int> a;
  poly(int v = 0) : a(1) {
    if ((v %= lbt) < 0) v += lbt;
    a[0] = v;
  }
  poly(const vector<int> &a) : a(a) {}
  int operator[](int i) const { return i < a.size() ? a[i] : 0; }
  int &operator[](int i) {
    if (i >= a.size()) a.resize(i + 1);
    return a[i];
  }
  poly(const initializer_list<int> &b) {
    int i = 0;
    for (initializer_list<int>::iterator it = b.begin(); it != b.end(); it++)
      (*this)[i++] = *it;
  }
  poly redeg(int d) const {
    if (d + 1 <= a.size()) return vector<int>(a.begin(), a.begin() + d + 1);
    vector<int> ans(a);
    ans.resize(d + 1);
    return ans;
  }
  int cal(int x) const {
    int ans = 0;
    int cur = 1;
    for (int i = 0; i < a.size(); i++) {
      ans = (ans + (long long)cur * a[i]) % lbt;
      cur = (long long)x * cur % lbt;
    }
    return ans;
  }
  poly ntt(int k, bool rev) const {
    static int ans[maxn];
    static int bit_rev[maxn];
    static int w[maxn];
    int g = rev ? (lbt + 1) / 3 : 3;
    int n = 1 << k;
    for (int i = 0; i < n; i++) {
      bit_rev[i] = (bit_rev[i >> 1] >> 1) | ((i & 1) << k - 1);
    }
    for (int i = 0; i < n; i++) {
      ans[bit_rev[i]] = (*this)[i];
    }
    for (int t = 1; t <= k; t++) {
      int w_n = fast_pow(g, (lbt - 1) / (1 << t));
      w[0] = 1;
      for (int j = 1; j < (1 << t - 1); j++)
        w[j] = (long long)w_n * w[j - 1] % lbt;
      for (int i = 0; i < n; i += (1 << t)) {
        int *ans0 = &ans[i];
        int *ans1 = &ans[i + (1 << t - 1)];
        int *W = w;
        for (int j = i; j < i + (1 << t - 1); j++) {
          int d = (long long)*W * *ans1 % lbt;
          *ans1 = *ans0 - d < 0 ? *ans0 - d + lbt : *ans0 - d;
          *ans0 = *ans0 + d >= lbt ? *ans0 + d - lbt : *ans0 + d;
          ans0++;
          ans1++;
          W++;
        }
      }
    }
    if (rev) {
      int rn = cal_rev(n);
      for (int i = 0; i < n; i++) ans[i] = (long long)ans[i] * rn % lbt;
    }
    return vector<int>(ans, ans + n);
  }
  poly operator+(const poly &b) const {
    vector<int> ans(max(a.size(), b.a.size()));
    for (int i = 0; i < ans.size(); i++) {
      ans[i] = (*this)[i] + b[i];
      if (ans[i] >= lbt) ans[i] -= lbt;
    }
    return ans;
  }
  poly operator-(const poly &b) const {
    vector<int> ans(max(a.size(), b.a.size()));
    for (int i = 0; i < ans.size(); i++) {
      ans[i] = (*this)[i] - b[i];
      if (ans[i] < 0) ans[i] += lbt;
    }
    return ans;
  }
  poly operator*(const poly &b) const {
    if (a.size() * b.a.size() < 1000) {
      vector<int> ans;
      ans.resize(a.size() + b.a.size() - 1);
      for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < b.a.size(); j++) {
          ans[i + j] = (ans[i + j] + (long long)a[i] * b.a[j]) % lbt;
        }
      }
      return ans;
    }
    int k = 0;
    while ((1 << k) <= a.size() + b.a.size() - 2) k++;
    poly fa = ntt(k, 0);
    poly fb = b.ntt(k, 0);
    for (int i = 0; i < (1 << k); i++) fa[i] = (long long)fa[i] * fb[i] % lbt;
    fa = fa.ntt(k, 1);
    return fa.redeg(a.size() + b.a.size() - 2);
  }
  poly inv(int k) const {
    poly ans(cal_rev(a[0]));
    ans = ans.redeg((1 << k) - 1);
    poly tmp, ta, fa;
    for (int i = 1; i <= k; i++) {
      int len = 1 << i;
      for (int j = 0; j < len; j++) ta[j] = (*this)[j];
      fa = ta.ntt(i, 0);
      tmp = ans.ntt(i, 0);
      for (int j = 0; j < len; j++) fa[j] = (long long)fa[j] * tmp[j] % lbt;
      ta = fa.ntt(i, 1);
      for (int j = 0; j < len / 2; j++) ta[j] = 0;
      fa = ta.ntt(i, 0);
      for (int j = 0; j < len; j++) fa[j] = (long long)fa[j] * tmp[j] % lbt;
      tmp = fa.ntt(i, 1);
      for (int i = len / 2; i < len; i++)
        ans[i] = (ans[i] - tmp[i] + lbt) % lbt;
    }
    return ans;
  }
  poly operator/(const poly &b) const {
    if (a.size() < b.a.size()) return poly(0);
    int n = a.size() - 1;
    int m = b.a.size() - 1;
    int k = 0;
    while ((1 << k) <= n - m) k++;
    poly at(vector<int>(a.rbegin(), a.rend()));
    poly bt(vector<int>(b.a.rbegin(), b.a.rend()));
    at = at.redeg(n - m);
    bt = bt.redeg(n - m);
    poly rbt = bt.inv(k);
    poly qt = (at * rbt).redeg(n - m);
    return vector<int>(qt.a.rbegin(), qt.a.rend());
  }
  poly operator%(const poly &b) const {
    poly q = (*this) / b;
    return ((*this) - b * q).redeg(b.a.size() - 2);
  }
  poly deriv() const {
    poly ans;
    ans.a.resize(a.size() - 1);
    for (int i = 1; i < a.size(); i++) {
      ans[i - 1] = (long long)i * a[i] % lbt;
    }
    return ans;
  }
  poly integ() const {
    poly ans;
    ans.a.resize(a.size() + 1);
    for (int i = 0; i < a.size(); i++) {
      ans[i + 1] = (long long)rev[i + 1] * a[i] % lbt;
    }
    return ans;
  }
  poly ln(int k) const {
    poly df = deriv();
    poly rf = inv(k);
    return (df * rf).redeg((1 << k) - 1).integ().redeg((1 << k) - 1);
  }
  poly exp(int k) const {
    poly ans(1);
    for (int t = 1; t <= k; t++) {
      ans = ans * (poly(1) + redeg((1 << t) - 1) - ans.ln(t));
    }
    return ans;
  }
  poly trans(int d) const {
    d = (d % lbt + lbt) % lbt;
    int pow = 1;
    poly A, B;
    for (int i = 0; i < a.size(); i++) {
      A[i] = (long long)fac[i] * a[i] % lbt;
      B[a.size() - i - 1] = (long long)pow * rfac[i] % lbt;
      pow = (long long)pow * d % lbt;
    }
    poly C = A * B;
    poly ans;
    for (int i = 0; i < a.size(); i++) {
      ans[i] = (long long)rfac[i] * C[a.size() + i - 1] % lbt;
    }
    return ans;
  }
};
poly fast_pow(const poly &a, int n, int t);
int n, k;
int h[maxn];
int main() {
  init();
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  if (k == 1) {
    printf("0");
    return 0;
  }
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += h[i] == h[i + 1];
  }
  cnt += h[n] == h[1];
  poly a;
  a[0] = 1;
  a[1] = k - 2;
  a[2] = 1;
  a = fast_pow(a, 2 * (n - cnt), n - cnt);
  a = a * poly(fast_pow(k, cnt));
  int ans = 0;
  for (int i = n - cnt + 1; i <= 2 * (n - cnt); i++) {
    ans = (ans + a[i]) % lbt;
  }
  printf("%d", ans);
  return 0;
}
poly fast_pow(const poly &a, int n, int t) {
  int bot = 0;
  while (!a[bot]) bot++;
  if ((long long)t * bot > n) return poly(0);
  int k = 0;
  while ((1 << k) <= n) k++;
  poly ta;
  for (int i = bot; i <= n; i++) ta[i - bot] = a[i];
  int ra = cal_rev(a[bot]);
  for (int i = 0; i < (1 << k); i++) ta[i] = (long long)ra * ta[i] % lbt;
  ta = ta.ln(k);
  for (int i = 0; i < (1 << k); i++) ta[i] = (long long)t * ta[i] % lbt;
  ta = ta.exp(k).redeg(n);
  int b = fast_pow(a[bot], t);
  for (int i = 0; i <= n; i++) ta[i] = (long long)b * ta[i] % lbt;
  poly ans;
  for (int i = t * bot; i <= n; i++) ans[i] = ta[i - t * bot];
  return ans;
}
