#include <bits/stdc++.h>
using namespace std;
int n, m;
long long int a[200009];
long long int c[2][1048576];
int cl[2];
long long int wlist[29];
long long int wlist_inv[29];
long long int expp(long long int p, long long int q) {
  long long int r = 1;
  long long int z = p;
  while (q) {
    if (q & 1) {
      r = (r * z) % 998244353;
    }
    q >>= 1;
    if (q) {
      z = (z * z) % 998244353;
    }
  }
  return r;
}
void inil() {
  long long int w = expp(3, 119);
  wlist[23] = w;
  wlist_inv[23] = expp(w, 998244353 - 2);
  for (int i = 22; i >= 0; i--) {
    wlist[i] = (wlist[i + 1] * wlist[i + 1]) % 998244353;
    wlist_inv[i] = (wlist_inv[i + 1] * wlist_inv[i + 1]) % 998244353;
  }
}
void fft(long long int *a, int al, bool invert) {
  int n = al;
  for (int i = 1, j = 0; i < n; i++) {
    int bit = n >> 1;
    for (; j >= bit; bit >>= 1) j -= bit;
    j += bit;
    if (i < j) swap(a[i], a[j]);
  }
  int li = 1;
  for (int len = 2; len <= n; len <<= 1) {
    long long int wlen = invert ? wlist_inv[li] : wlist[li];
    for (int i = 0; i < n; i += len) {
      long long int w = 1;
      for (int j = 0; j < len / 2; j++) {
        long long int u = a[i + j], v = (a[i + j + len / 2] * w) % 998244353;
        a[i + j] = (u + v) % 998244353;
        a[i + j + len / 2] = (u + 998244353 - v) % 998244353;
        w = (w * wlen) % 998244353;
      }
    }
    li++;
  }
  if (invert) {
    static unordered_map<int, long long int> memoi;
    if (memoi.find(n) == memoi.end()) memoi[n] = expp(n, 998244353 - 2);
    long long int invzn = memoi[n];
    for (int i = 0; i < n; i++) a[i] = (a[i] * invzn) % 998244353;
  }
}
long long int fa[1048576];
void multiply(long long int *a, int al, long long int *res, int &rl) {
  int n = 1;
  while (n < al * 2) n <<= 1;
  for (int i = 0; i < al; i++) fa[i] = a[i];
  for (int i = al; i < n; i++) fa[i] = 0;
  fft(fa, n, false);
  for (int i = 0; i < n; i++) fa[i] = (fa[i] * fa[i]) % 998244353;
  fft(fa, n, true);
  rl = n;
  for (int i = 0; i < n; i++) res[i] = fa[i];
}
void expppoly(int q, int cur) {
  if (q == 0) {
    c[cur][0] = 1;
    cl[cur] = 1;
    return;
  }
  if (q & 1) {
    expppoly(q - 1, cur ^ 1);
    int i, j;
    cl[cur] = cl[cur ^ 1] + 2;
    for (i = 0; i < cl[cur]; i++) c[cur][i] = 0;
    for (i = 0; i < cl[cur ^ 1]; i++) {
      c[cur][i] = (c[cur][i] + c[cur ^ 1][i]) % 998244353;
      c[cur][i + 1] = (c[cur][i + 1] + c[cur ^ 1][i] * (m - 2)) % 998244353;
      c[cur][i + 2] = (c[cur][i + 2] + c[cur ^ 1][i]) % 998244353;
    }
  } else {
    expppoly(q / 2, cur ^ 1);
    int i, j;
    multiply(c[cur ^ 1], cl[cur ^ 1], c[cur], cl[cur]);
    while (cl[cur] > 1 && c[cur][cl[cur] - 1] == 0) cl[cur]--;
  }
}
int main() {
  inil();
  int i, j, k, l;
  int t = 1, tv = 0;
  while (t--) {
    scanf("%d %d", &n, &m);
    int cnt = 0;
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    if (m == 1) {
      printf("0\n");
      return 0;
    }
    for (i = 1; i < n; i++) {
      if (a[i] != a[i - 1]) {
        cnt++;
      }
    }
    if (a[0] != a[n - 1]) cnt++;
    expppoly(cnt, 0);
    long long int res = 0;
    for (i = cnt + 1; i < cl[0]; i++) {
      res = (res + c[0][i]) % 998244353;
    }
    res = (res * expp(m, n - cnt)) % 998244353;
    printf("%lld\n", res);
  }
}
