#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long pow(long long x, long long v) {
  if (v == 0) return 1LL;
  if (v % 2) return (x % MOD) * pow(x % MOD, v - 1) % MOD;
  return pow((x * x) % MOD, v / 2) % MOD;
}
int main() {
  int n;
  long long x, sum = 0, v, mx = 0;
  scanf("%d%lld", &n, &x);
  map<long long, int> cnt;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%lld", &a[i]), sum += a[i], mx = max(mx, a[i]);
  for (int i = 0; i < n; ++i) cnt[sum - a[i]]++;
  for (map<long long, int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {
    v = it->first;
    if (it->second % x == 0) {
      cnt[v + 1] += it->second / x;
    } else
      break;
  }
  v = min(v, sum);
  printf("%lld", pow(x, v));
  return 0;
}
