#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 100005;
long long quickpow(int p, long long x) {
  long long res = 1, base = p;
  while (x) {
    if (x & 1) res = res * base % mod;
    base = base * base % mod;
    x >>= 1;
  }
  return res;
}
int data[maxn], n, x;
multiset<int> s;
multiset<int>::iterator it;
int solve() {
  for (int i = 1; i <= n; i++) s.insert(data[i]);
  while (s.size() >= x) {
    it = s.begin();
    int fr = (*it), la;
    for (int i = 1; i < x; i++) it++;
    la = (*it);
    if (fr == la) {
      for (int i = 1; i <= x; i++) {
        s.erase(s.begin());
      }
      s.insert(fr + 1);
    } else
      break;
  }
  return *s.begin();
}
int main() {
  scanf("%d%d", &n, &x);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", data + i);
    sum += data[i];
  }
  int lef = data[n];
  for (int i = 1; i <= n; i++) data[i] = lef - data[i];
  long long res = quickpow(x, sum - lef);
  res = res * quickpow(x, min(solve(), lef)) % mod;
  printf("%d\n", res);
}
