#include <bits/stdc++.h>
using namespace std;
const int maxn = 524288;
const int mod = 998244353, _k = 119, _b = 23, _g = 3;
int n, m, i, j, num[200005];
int c0 = 0, c1 = 0;
inline void inc(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline void dec(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
inline int qp(int x, int y) {
  int z = 1;
  while (y) {
    if (y & 1) z = 1ll * z * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return z;
}
namespace polynomial {
namespace basic {
int fac[maxn + 5], inv[maxn + 5], fi[maxn + 5], lg[maxn + 5], pw[maxn + 5],
    w[maxn + 5], iw[maxn + 5];
bool tag = 0;
inline void init() {
  tag = 1;
  int i;
  for ((i) = (2); (i) <= (maxn); ++(i)) lg[i] = lg[i >> 1] + 1;
  pw[0] = 1;
  for ((i) = 1; (i) <= (lg[maxn]); ++(i)) pw[i] = pw[i - 1] * 2;
  fac[0] = fac[1] = inv[1] = fi[0] = fi[1] = 1;
  for ((i) = (2); (i) <= (maxn); ++(i)) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;
    fi[i] = 1ll * fi[i - 1] * inv[i] % mod;
  }
  w[0] = 1;
  w[1] = qp(_g, (mod - 1) / maxn);
  for ((i) = (2); (i) <= (maxn); ++(i)) w[i] = 1ll * w[i - 1] * w[1] % mod;
  iw[maxn] = qp(w[maxn], mod - 2);
  for ((i) = (long long)((maxn)-1); (i) >= 0; --(i))
    iw[i] = 1ll * iw[i + 1] * w[1] % mod;
  if (iw[0] != 1) {
    puts("wrong iw!!!!!!!!!!!!!!!!!");
    exit(-1);
  }
}
int rev[maxn + 5], a[maxn + 5], b[maxn + 5];
inline int getrev(int x) {
  if (!tag) init();
  int i, s = 1;
  while (s < x) s *= 2;
  rev[0] = 0;
  for ((i) = 1; (i) <= (s - 1); ++(i))
    rev[i] = ((rev[i >> 1] >> 1) | ((i & 1) << (lg[s] - 1)));
  return s;
}
inline void ntt(int *a, int n, int *w) {
  if (!tag) init();
  int i, j, k;
  for ((i) = 0; (i) < (n); ++(i))
    if (rev[i] < i) swap(a[i], a[rev[i]]);
  for (i = 1; i < n; i <<= 1) {
    int ys = maxn / i / 2;
    for (j = 0; j < n; j += i + i) {
      int *t = w;
      for ((k) = 0; (k) < (i); ++(k)) {
        int x = a[j + k], y = 1ll * a[j + k + i] * (*t) % mod;
        a[j + k] = x + y;
        if (a[j + k] >= mod) a[j + k] -= mod;
        a[j + k + i] = x - y;
        if (a[j + k + i] < 0) a[j + k + i] += mod;
        t += ys;
      }
    }
  }
}
inline vector<int> mul(const vector<int> &aa, const vector<int> &bb) {
  vector<int> ans;
  long long br = 1ll * aa.size() * bb.size(),
            ft =
                1ll * (aa.size() + bb.size()) * lg[aa.size() + bb.size()] * 10 +
                100;
  if (br < ft) {
    while (ans.size() + 1 < aa.size() + bb.size()) ans.push_back(0);
    int i, j;
    for ((i) = 0; (i) < (aa.size()); ++(i))
      for ((j) = 0; (j) < (bb.size()); ++(j))
        inc(ans[i + j], 1ll * aa[i] * bb[j] % mod);
  } else {
    int len = getrev(aa.size() + bb.size()), i;
    for ((i) = 0; (i) < (len); ++(i)) a[i] = b[i] = 0;
    for ((i) = 0; (i) < (aa.size()); ++(i)) a[i] = aa[i];
    for ((i) = 0; (i) < (bb.size()); ++(i)) b[i] = bb[i];
    ntt(a, len, w);
    ntt(b, len, w);
    for ((i) = 0; (i) < (len); ++(i)) a[i] = 1ll * a[i] * b[i] % mod;
    ntt(a, len, iw);
    int inv = qp(len, mod - 2);
    for ((i) = 0; (i) < (len); ++(i)) ans.push_back(1ll * a[i] * inv % mod);
  }
  while (ans.size() > c1) ans.pop_back();
  while (!ans.empty() && !ans.back()) ans.pop_back();
  return ans;
}
};  // namespace basic
struct poly {
  vector<int> v;
  inline void clear() { v.clear(); }
  inline int size() { return v.size(); }
  inline bool empty() { return v.empty(); }
  inline int back() { return v.back(); }
  inline void pop_back() { v.pop_back(); }
  inline void push_back(int x) { v.push_back(x); }
  inline void read(int n) {
    clear();
    while (n--) {
      int x;
      scanf("%d", &x);
      v.push_back(x);
    }
  }
  inline void print() {
    for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
      printf("%d ", *it);
    puts("");
  }
  inline void print(int n) {
    int i;
    for (i = 0; i < n; i++)
      if (i < v.size())
        printf("%d ", v[i]);
      else
        printf("0 ");
    puts("");
  }
  inline int operator[](const int &x) { return v[x]; }
  inline poly operator+(const poly &x) const {
    vector<int> s;
    int i;
    for (i = 0; i < x.v.size() || i < v.size(); i++) {
      int t = 0;
      if (i < v.size()) inc(t, v[i]);
      if (i < x.v.size()) inc(t, x.v[i]);
      s.push_back(t);
    }
    return (poly){s};
  }
  inline poly operator-(const poly &x) const {
    vector<int> s;
    int i;
    for (i = 0; i < x.v.size() || i < v.size(); i++) {
      int t = 0;
      if (i < v.size()) inc(t, v[i]);
      if (i < x.v.size()) dec(t, x.v[i]);
      s.push_back(t);
    }
    return (poly){s};
  }
  inline poly operator*(const int &x) const {
    vector<int> s;
    int i;
    for (i = 0; i < v.size(); i++) s.push_back(1ll * x * v[i] % mod);
    return (poly){s};
  }
  inline poly operator*(const poly &x) const {
    return (poly){basic::mul(v, x.v)};
  }
  inline void derivation() {
    int i;
    for ((i) = 0; (i) < (v.size()); ++(i))
      v[i] = 1ll * v[i + 1] * (i + 1) % mod;
    v.pop_back();
  }
  inline void integral() {
    int i;
    v.push_back(0);
    for ((i) = (v.size() - 1); (i) >= 1; --(i))
      v[i] = 1ll * v[i - 1] * basic::inv[i] % mod;
  }
  inline void size_down(int x) {
    while (v.size() > x) v.pop_back();
  }
};
};  // namespace polynomial
using namespace polynomial;
poly solve(int k) {
  poly a;
  a.push_back(1);
  poly b;
  b.push_back(1);
  b.push_back((m - 2) % mod);
  b.push_back(1);
  int i;
  for ((i) = 0; (i) <= (18); ++(i)) {
    if ((1 << i) > k) break;
    if (i != 0) b = b * b;
    if ((k >> i) & 1) a = a * b;
  }
  return a;
}
int main() {
  scanf("%d%d", &n, &m);
  for ((i) = 1; (i) <= (n); ++(i)) {
    scanf("%d", &num[i]);
  }
  for ((i) = 1; (i) <= (n); ++(i)) {
    if (num[i] == num[i % n + 1]) {
      c0++;
    } else {
      c1++;
    }
  }
  if (!c1) {
    puts("0");
    return 0;
  }
  poly ans = solve(c1);
  int sum = 0, len = ans.size();
  for (i = 0; i < len && i < c1; i++) inc(sum, ans[i]);
  cout << 1ll * sum * qp(m, c0) % mod << endl;
  return 0;
}
