#include <bits/stdc++.h>
using namespace std;
void sc() {}
template <typename T, typename... Args>
void sc(T& a, Args&... args) {
  cin >> a, sc(args...);
}
template <typename T>
void pr(T a) {
  cout << a;
}
template <typename T, typename... Args>
void pr(T a, Args... args) {
  cout << a << " ", pr(args...);
}
template <typename T>
void prl(T a) {
  cout << a << "\n";
}
template <typename T, typename... Args>
void prl(T a, Args... args) {
  cout << a << " ", prl(args...);
}
template <typename T>
int sz(const T& a) {
  return (int)a.size();
}
const int MAXN = 2e3 + 1;
long long int mod = 998244353;
long long int dp[MAXN][2 * MAXN + 3];
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n;
  long long int k;
  sc(n, k);
  int ans[n];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    sc(ans[i]);
  dp[0][n + 1] = 1;
  int toloop = 2 * n + 3;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    for (__typeof(toloop) j = (0) - ((0) > (toloop));
         j != (toloop) - ((0) > (toloop)); j += 1 - 2 * ((0) > (toloop))) {
      if (ans[i - 1] != ans[i % n]) {
        dp[i][j] = ((k - 2) * dp[i - 1][j]) % mod;
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;
      } else {
        dp[i][j] = (k * dp[i - 1][j]) % mod;
      }
    }
  }
  long long int fin = 0;
  for (__typeof(toloop) i = (n + 2) - ((n + 2) > (toloop));
       i != (toloop) - ((n + 2) > (toloop));
       i += 1 - 2 * ((n + 2) > (toloop))) {
    fin = (fin + dp[n][i]) % mod;
  }
  prl(fin);
  return 0;
}
