#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
map<long long, long long> book;
map<long long, long long>::iterator it;
long long a[100005];
long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return ans;
}
int main() {
  long long n, x;
  scanf("%lld%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++) {
    book[sum - a[i]]++;
  }
  for (it = book.begin(); it != book.end(); it++) {
    if (it->second >= x) {
      long long tmp = it->second / x;
      book[it->first + 1] += tmp;
      book[it->first] -= tmp * x;
    }
  }
  it = book.begin();
  while (it->second == 0) it++;
  printf("%lld\n", qp(x, min(it->first, sum)));
  return 0;
}
