#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long pw(long long base, long long pwr, long long x) {
  if (pwr == 0) return 1;
  if (pwr & 1LL)
    return (x * pw(((base * x) % mod), pwr - 1, x)) % mod;
  else {
    long long ret = pw(base, pwr >> 1LL, x);
    return (ret * ret) % mod;
  }
}
int main() {
  long long n, x;
  cin >> n >> x;
  long long arr[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    long long tmp = sum - arr[i];
    mp[tmp]++;
  }
  map<long long, long long>::iterator it = mp.begin();
  while (it != mp.end()) {
    if (it->second >= x) {
      mp[it->first + 1] += it->second / x;
      it->second = it->second % x;
      it = mp.begin();
    } else
      it++;
  }
  long long ans = sum;
  for (auto it : mp)
    if (it.second != 0) ans = min(it.first, ans);
  cout << pw(x, ans, x);
  return 0;
}
