#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long pw(long long a, long long b, long long m = MOD) {
  if (b == 0) return 1;
  if (b & 1) return a * pw(a, b - 1) % m;
  return pw(a * a % m, b / 2);
}
void solve() {
  long long n, x;
  cin >> n >> x;
  vector<long long> v(n);
  long long sum = 0;
  for (long long i = 0; i < n; i++) cin >> v[i], sum += v[i];
  long long ans = 0;
  long long tp = *max_element(v.begin(), v.end());
  map<long long, long long> cnt;
  for (long long i = 0; i < n; i++) {
    v[i] = tp - v[i];
    cnt[v[i]]++;
  }
  ans += (sum - tp);
  long long i = 0;
  while (cnt[i] % x == 0) {
    cnt[i + 1] += cnt[i] / x;
    i++;
  }
  ans = pw(x, ans + min(i, tp));
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) solve();
  return 0;
}
