#include <bits/stdc++.h>
using namespace std;
int superRand() {
  if (RAND_MAX == (1 << 15) - 1) {
    return (rand() << 15) + rand();
  }
  return rand();
}
struct Node {
  int key, prior, sz;
  Node *l, *r;
  Node() : l(nullptr), r(nullptr), sz(0) {}
  Node(int key_)
      : l(nullptr), r(nullptr), prior(superRand()), sz(1), key(key_) {}
};
typedef Node* Pnode;
int get_size(Pnode root) {
  if (root != nullptr) return root->sz;
  return 0;
}
void update(Pnode root) {
  if (root != nullptr) {
    root->sz = get_size(root->l) + get_size(root->r) + 1;
  }
}
void split(Pnode root, Pnode& l, Pnode& r, int x) {
  if (root == nullptr) return void(l = r = nullptr);
  if (root->key < x) {
    split(root->r, root->r, r, x);
    l = root;
  } else {
    split(root->l, l, root->l, x);
    r = root;
  }
  update(r);
  update(l);
}
void merge(Pnode& root, Pnode l, Pnode r) {
  if (!l || !r) return void(root = l ? l : r);
  if (l->prior > r->prior) {
    merge(l->r, l->r, r);
    root = l;
  } else {
    merge(r->l, l, r->l);
    root = r;
  }
  update(root);
}
void insert(Pnode root, Pnode ins) {
  Pnode l, r;
  split(root, l, r, ins->key);
  merge(root, l, ins);
  merge(root, root, r);
}
void erase(Pnode root, int x) {
  Pnode l, m, r;
  split(root, l, m, x);
  split(m, m, r, x + 1);
  merge(root, l, r);
}
bool find(Pnode root, int x) {
  if (root == nullptr) return false;
  if (root->key == x) return true;
  if (root->key > x) {
    return find(root->l, x);
  }
  return find(root->r, x);
}
int getkth(Pnode root, int k) {
  if (get_size(root->l) == k) return root->key;
  if (get_size(root->l) > k) return getkth(root->l, k);
  return getkth(root->r, k - get_size(root->l) - 1);
}
int get_num(Pnode root, int x) {
  if (root == nullptr) return -1;
  if (root->key == x) return get_size(root->l);
  if (root->key > x) return get_num(root->l, x);
  return get_num(root->r, x) + get_size(root->l) + 1;
}
struct num {
  int val, index;
  num(){};
  const bool operator<(const num& other) {
    return val > other.val || (val == other.val && index < other.index);
  }
};
struct ask {
  int k, pos, index;
  ask(){};
  const bool operator<(const ask& other) { return k < other.k; }
};
int32_t main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  vector<vector<int>> dp(n + 1, vector<int>(2 * n + 3));
  dp[0][n + 1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = -i; j <= i; j++)
      if (h[i - 1] != h[i % n])
        dp[i][j + n + 1] =
            (dp[i - 1][j + n + 1] * 1ll * (k - 2) + dp[i - 1][j - 1 + n + 1] +
             dp[i - 1][j + 1 + n + 1]) %
            998244353;
      else
        dp[i][j + n + 1] = (dp[i - 1][j + n + 1] * 1ll * k) % 998244353;
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[n][i + n + 1];
  cout << ans % 998244353;
}
