#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
long long power(long long a, long long p, long long mod) {
  if (p == 0) return 1;
  long long ans = power(a, p / 2, mod);
  ans = (ans * ans) % mod;
  if (p % 2) ans = (ans * a) % mod;
  return ans;
}
struct NTT {
  int N;
  vector<int> perm;
  int mod, root, inv, pw;
  NTT(int mod, int root, int inv, int pw)
      : mod(mod), root(root), inv(inv), pw(pw) {}
  void precalculate() {
    perm.resize(N);
    perm[0] = 0;
    for (int k = 1; k < N; k <<= 1) {
      for (int i = 0; i < k; i++) {
        perm[i] <<= 1;
        perm[i + k] = 1 + perm[i];
      }
    }
  }
  void fft(vector<long long> &v, bool invert = false) {
    if (v.size() != perm.size()) {
      N = v.size();
      assert(N && (N & (N - 1)) == 0);
      precalculate();
    }
    for (int i = 0; i < N; i++)
      if (i < perm[i]) swap(v[i], v[perm[i]]);
    for (int len = 2; len <= N; len <<= 1) {
      long long factor = invert ? inv : root;
      for (int i = len; i < pw; i <<= 1) factor = (factor * factor) % mod;
      for (int i = 0; i < N; i += len) {
        long long w = 1;
        for (int j = 0; j < len / 2; j++) {
          long long x = v[i + j], y = (w * v[i + j + len / 2]) % mod;
          v[i + j] = (x + y) % mod;
          v[i + j + len / 2] = (x - y + mod) % mod;
          w = (w * factor) % mod;
        }
      }
    }
    if (invert) {
      long long n1 = power(N, mod - 2, mod);
      for (long long &x : v) x = (x * n1) % mod;
    }
  }
  vector<long long> multiply(vector<long long> a, vector<long long> b) {
    int n = 1;
    while (n < a.size() + b.size()) n <<= 1;
    a.resize(n);
    b.resize(n);
    fft(a);
    fft(b);
    for (int i = 0; i < n; i++) a[i] = (a[i] * b[i]) % mod;
    fft(a, true);
    return a;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  a.erase(unique(a.begin(), a.end()), a.end());
  if (a[0] == a.back()) a.pop_back();
  int m = a.size();
  NTT fft(998244353, 15311432, 469870224, 1 << 23);
  vector<long long> base = {1, k - 2, 1};
  base.resize(1 << 19);
  fft.fft(base);
  for (long long &x : base) x = power(x, m, M);
  fft.fft(base, true);
  while (base.size() && base.back() == 0) base.pop_back();
  long long ans = 0;
  for (int i = m + 1; i < base.size(); i++) ans += base[i];
  ans %= M;
  cout << (ans * power(k, n - m, M)) % M << endl;
}
