#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (int i = 0; i < (n); i++) cin >> v[i];
  vector<vector<long long>> dp(2001, vector<long long>(4001, 0));
  dp[0][2000] = 1;
  for (int i = 0; i < (n); i++) {
    if (v[i] == v[(i + 1) % n]) {
      for (int j = 0; j < (4001); j++) {
        dp[i + 1][j] += (dp[i][j] * k) % 998244353ll;
        dp[i + 1][j] %= 998244353ll;
      }
    } else {
      for (int j = 0; j < (4001); j++) {
        dp[i + 1][j] += (dp[i][j] * (k - 2)) % 998244353ll;
        dp[i + 1][j] %= 998244353ll;
        if (j != 0) {
          dp[i + 1][j - 1] += dp[i][j];
          dp[i + 1][j - 1] %= 998244353ll;
        }
        if (j != 4000) {
          dp[i + 1][j + 1] += dp[i][j];
          dp[i + 1][j + 1] %= 998244353ll;
        }
      }
    }
  }
  long long otv = 0;
  for (int i = 2001; i < (4001); i++) {
    otv += dp[n][i];
    otv %= 998244353ll;
  }
  cout << otv;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  while (q--) {
    solve();
    cout << '\n';
  }
}
