#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
void _(long long& a, long long b) {
  a = (a % 1000000007 + b % 1000000007) % 1000000007;
  a = (a + 1000000007) % 1000000007;
}
long long cl(long long a, long long b) { return (a / b) + (!(!(a % b))); }
long long modexp(long long base, long long power) {
  long long res = 1;
  while (power) {
    if (power & 1) res = (res * base) % 1000000007;
    power >>= 1;
    base = (base * base) % 1000000007;
  }
  return res;
}
long long invmod(long long num) { return modexp(num, 1000000007 - 2); }
double logpow(double base, long long exp) {
  double res = 0.0;
  while (exp) {
    if (exp & 1) res += base;
    exp >>= 1;
    base += base;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long x;
  cin >> x;
  long long a[n];
  long long sm = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sm += a[i];
  }
  vector<long long> v;
  for (long long i = 0; i < n; ++i) {
    v.push_back(sm - a[i]);
  }
  sort(v.rbegin(), v.rend());
  while (1) {
    long long d = v.back();
    long long cnt = 0;
    while (v.back() == d) {
      cnt++;
      v.pop_back();
    }
    if (cnt % x) {
      cout << modexp(x, min(d, sm));
      return 0;
    } else {
      cnt /= x;
      for (long long i = 0; i < cnt; ++i) {
        v.push_back(d + 1);
      }
    }
  }
}
