#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n, m, b, c, k, temp, x, y;
const int MAXN = 1e5 + 11;
inline long long max(long long a, long long b) { return ((a > b) ? a : b); }
inline long long min(long long a, long long b) { return ((a > b) ? b : a); }
inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
inline vector<long long> read(int n) {
  vector<long long> v(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
int a[2001];
const int mod = 998244353;
long long dp[2001][5011];
void solveforthiscase(const int& test) {
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return;
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1 || a[1] == a[2]) {
    dp[1][3000 + 0] = k;
  } else {
    dp[1][3000 - 1] = 1;
    dp[1][3000 + 1] = 1;
    dp[1][3000 + 0] = k - 2;
  }
  for (int i = 2; i <= n; i++) {
    for (int diff = 1000; diff <= 5000; diff++) {
      if (a[i] == a[(i % n) + 1])
        dp[i][diff] = (k * (dp[i - 1][diff])) % mod;
      else
        dp[i][diff] = ((dp[i - 1][diff - 1] + dp[i - 1][diff + 1])) % mod +
                      ((k - 2) * dp[i - 1][diff]) % mod;
      dp[i][diff] %= mod;
    }
  }
  long long ans = 0;
  for (int i = 3001; i <= 5000; i++) ans += dp[n][i], ans %= mod;
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t start, end;
  start = clock();
  int test = 1;
  for (int i = 1; i <= test; i++) solveforthiscase(i);
  end = clock();
  long double t_t = (long double)(end - start) / (long double)(CLOCKS_PER_SEC);
  cerr << (long double)t_t * 1000 << " ms ";
}
