#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long MOD = 998244353;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 2001;
int n, k, a[N];
long long dp[N][3 * N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[0][N] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = -n; j <= n; j++) {
      int nxt = i + 1;
      if (nxt == n + 1) nxt = 1;
      if (a[i] == a[nxt]) {
        dp[i][j + N] = (dp[i - 1][j + N] * k) % MOD;
      } else {
        dp[i][j + N] = (dp[i][j + N] + dp[i - 1][j + N] * (k - 2)) % MOD;
        dp[i][j + N] = (dp[i][j + N] + dp[i - 1][j - 1 + N]) % MOD;
        dp[i][j + N] = (dp[i][j + N] + dp[i - 1][j + 1 + N]) % MOD;
      }
    }
  }
  long long res = 0;
  for (int i = -n; i < 0; i++) res = (res + dp[n][i + N]) % MOD;
  cout << res;
  return 0;
}
