#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<unordered_map<long long, long long>> dp(n + 1);
  vector<long long> arr(n);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  unordered_map<long long, long long> current;
  current[0] = 1;
  for (int i = 0; i < n; ++i) {
    long long here = arr[i];
    long long nxt = arr[(i + 1) % n];
    unordered_map<long long, long long> nxt_map;
    if (here == nxt) {
      for (auto [j, times] : current) {
        nxt_map[j] += times * k;
        nxt_map[j] %= mod;
      }
    } else {
      for (auto [j, times] : current) {
        nxt_map[j] += times * (k - 2);
        nxt_map[j] %= mod;
      }
      for (auto [j, times] : current) {
        nxt_map[j + 1] += times;
        nxt_map[j - 1] += times;
        nxt_map[j + 1] %= mod;
        nxt_map[j - 1] %= mod;
      }
    }
    current = nxt_map;
  }
  long long res = 0;
  for (auto [i, j] : current) {
    if (i > 0) res += j;
    res %= mod;
  }
  cout << res << endl;
}
