#include <bits/stdc++.h>
using namespace std;
template <class T, class V>
struct crtp {
  typedef
      typename conditional<is_const<typename remove_pointer<T>::type>::value,
                           const V *, V *>::type type;
};
template <class D>
struct AdditiveOps {};
template <int M, class T = int, class MT = T>
struct IntM : AdditiveOps<IntM<M, T, MT>> {
 private:
  struct PrivateTag {};
  explicit constexpr IntM(T v, PrivateTag) : v(v) {}

 public:
  IntM() = default;
  constexpr IntM(T v) : v(nm(v).v) {}
  static constexpr IntM d(T v) { return IntM(v, PrivateTag()); }
  static constexpr IntM nm(T v) {
    T p = v % M;
    return IntM(p >= 0 ? p : p + M, PrivateTag());
  }
  IntM &operator+=(IntM i) {
    v += i.v;
    if (v >= M) v -= M;
    return *this;
  }
  IntM &operator*=(const IntM i) {
    v = (MT)v * i.v % M;
    return *this;
  }
  IntM operator*(const IntM i) const { return IntM(*this) *= i; }
  friend istream &operator>>(istream &is, IntM &i) { return is >> i.v; }
  friend ostream &operator<<(ostream &os, const IntM &i) { return os << i.v; }
  IntM inv() const {
    pair<T, T> p(v, M);
    pair<T, T> x(0, 1);
    pair<T, T> y(1, 0);
    while (p.second) {
      MT q = p.first / p.second;
      p = pair<T, T>(p.second, p.first % p.second);
      x = pair<T, T>(x.second - q * x.first, x.first);
      y = pair<T, T>(y.second - q * y.first, y.first);
    }
    return IntM::d(x.second < 0 ? x.second + M : x.second);
  }
  IntM &operator/=(const IntM i) { return *this *= i.inv(); }
  IntM operator/(const IntM i) const { return IntM(*this) /= i; }
  T v;
};
template <class T, class S, class E>
S pow(T x, S s, E e) {
  for (; e; e >>= 1) {
    if (e & 1) s *= x;
    x *= x;
  }
  return s;
}
template <class T = int>
T fact(int n) {
  static vector<T> v = {1};
  for (int i = v.size(); i <= n; ++i) {
    v.push_back(v.back() * i);
  }
  return v[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int p;
  cin >> p;
  int f = p;
  int diff = 0;
  int same = 0;
  for (int i = 1; i < n; ++i) {
    int h;
    cin >> h;
    if (h != p) {
      ++diff;
    } else {
      ++same;
    }
    p = h;
  }
  if (f != p) {
    ++diff;
  } else {
    ++same;
  }
  IntM<998244353, long long> sol = 0;
  for (int i = 0; i < diff; ++i) {
    for (int j = i + 1; i + j <= diff; ++j) {
      int l = diff - (i + j);
      sol += fact<IntM<998244353, long long>>(diff) /
             (fact<IntM<998244353, long long>>(i) *
              fact<IntM<998244353, long long>>(j) *
              fact<IntM<998244353, long long>>(l)) *
             pow(IntM<998244353, long long>::d(k - 2),
                 IntM<998244353, long long>(1), l);
    }
  }
  sol *= pow(IntM<998244353, long long>::d(k), IntM<998244353, long long>(1),
             same);
  cout << sol << endl;
  return 0;
}
