#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007L;
long long power1(long long k, long long n, long long result) {
  if (n == 0) return result;
  long long k1 = k * k;
  k1 %= MOD;
  if (n % 2) {
    result *= k;
    result %= MOD;
    return power1(k1, (n - 1) / 2, result);
  } else {
    return power1(k1, n / 2, result);
  }
}
long long power(long long k, long long n) { return power1(k, n, 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, x;
  cin >> n >> x;
  vector<long long> a;
  long long sum = 0;
  for (long long i = 0; i < n; ++i) {
    long long ai;
    cin >> ai;
    a.push_back(ai);
    sum += ai;
  }
  sort(a.rbegin(), a.rend());
  long long last = a[0];
  long long count = 1;
  long long i = 1;
  while (i < n && last > 0) {
    if (a[i] == last) {
      ++count;
      ++i;
    } else {
      if (count % x) {
        count %= x;
        break;
      }
      --last;
      count /= x;
    }
  }
  while (last > 0 && count % x == 0) {
    --last;
    count /= x;
  }
  long long result = power(x, sum - last);
  cout << result << endl;
  return 0;
}
