#include <bits/stdc++.h>
using namespace std;
void RI(int& x) {
  x = 0;
  char c = getchar();
  while (!(c >= '0' && c <= '9' || c == '-')) c = getchar();
  bool flag = 1;
  if (c == '-') {
    flag = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (!flag) x = -x;
}
void RII(int& x, int& y) { RI(x), RI(y); }
void RIII(int& x, int& y, int& z) { RI(x), RI(y), RI(z); }
void RC(char& c) {
  c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
}
char RC() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const long long mod = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 1e9;
const double EPS = 1e-8;
long long POW(long long m, long long n) {
  if (n == 1) return m;
  if (n == 0) return 1LL;
  long long tmp = POW(m, n / 2);
  if (n & 1) return tmp * tmp % mod * m % mod;
  return tmp * tmp % mod;
}
map<long long, int> mmap;
void insert(long long t, int num) {
  if (mmap.find(t) == mmap.end()) {
    mmap.insert(make_pair(t, num));
  } else {
    mmap.find(t)->second += num;
  }
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long sum = 0;
  int n, x;
  RII(n, x);
  for (int i = 1; i <= n; i++) {
    int t;
    RI(t);
    sum += t;
    mmap[t]++;
    while (t > 0 && mmap[t] == x) {
      mmap[t] = 0;
      mmap[--t]++;
    }
  }
  long long maxx = 0;
  for (map<long long, int>::iterator it = mmap.begin(); it != mmap.end();
       it++) {
    if (it->second != 0) maxx = it->first;
  }
  cout << POW(x, sum - maxx) << endl;
}
