#include <bits/stdc++.h>
using namespace std;
int a[200005];
long long comb[2003][2003];
long long powk[3][2003];
int main() {
  ios::sync_with_stdio(0);
  int n;
  long long k;
  cin >> n >> k;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i == j)
        comb[i][j] = 1ll;
      else if (i < j)
        comb[i][j] = 0ll;
      else
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % 998244353ll;
    }
  }
  for (int i = 0; i < 3; i++) {
    powk[i][0] = 1ll;
    for (int j = 1; j <= n; j++)
      powk[i][j] = (powk[i][j - 1] * (k - i)) % 998244353ll;
  }
  for (int i = 0; i < n; i++) cin >> a[i];
  int x = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != a[(i + 1) % n]) x++;
  }
  long long ans = 0;
  for (int i = 1; i <= x; i++) {
    for (int j = 0; j < i && i + j <= x; j++) {
      long long adder = (comb[x][i] * comb[x - i][j]) % 998244353ll;
      adder = (adder * powk[0][n - x]) % 998244353ll;
      adder = (adder * powk[2][x - (i + j)]) % 998244353ll;
      ans = (ans + adder) % 998244353ll;
    }
  }
  cout << ans << "\n";
  return 0;
}
