#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long pw(long long x, long long n) {
  if (n == 0) return 1;
  long long res = pw(x, n / 2);
  res *= res;
  res %= MOD;
  if (n % 2) res *= x;
  res %= MOD;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  long long sum = 0;
  long long mx = (int)-1;
  vector<long long> pows(n);
  for (int i = 0; i < n; i++) {
    cin >> pows[i];
    sum += pows[i];
    mx = max(mx, pows[i]);
  }
  long long red = sum - mx;
  for (int i = 0; i < n; i++) {
    pows[i] = sum - pows[i];
    pows[i] -= red;
  }
  sort(pows.rbegin(), pows.rend());
  long long numPow = red;
  int exp = 0;
  int curAcc = 0;
  for (int i = pows.size() - 1; i >= 0; i--) {
    if (exp == pows[i])
      curAcc++;
    else {
      if (curAcc % x == 0) {
        numPow++;
        curAcc /= x;
        exp++;
        i++;
      } else
        break;
    }
  }
  while (curAcc % x == 0) {
    numPow++;
    curAcc /= x;
    exp++;
  }
  cout << pw(x, min(sum, numPow));
}
