#include <bits/stdc++.h>
using namespace std;
long long pw(long long x, long long n) {
  if (n == 0) return 1;
  if (n % 2)
    return x * pw(x, n - 1) % 1000000007;
  else {
    long long ret = pw(x, n / 2);
    return ret * ret % 1000000007;
  }
}
map<long long, long long> d;
int n;
long long x, a[100001];
int idx;
int main() {
  scanf("%d %lld", &n, &x);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    d[sum - a[i]]++;
  }
  while (1) {
    map<long long, long long>::iterator it = d.begin();
    if (it->second % x) {
      printf("%lld\n", pw(x, min(sum, it->first)));
      return 0;
    }
    d[it->first + 1] += it->second / x;
    d.erase(it);
  }
}
