#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
long long modexp(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2)
    return (x * modexp((x * x) % 1000000007, (n - 1) / 2)) % 1000000007;
  else
    return modexp((x * x) % 1000000007, n / 2) % 1000000007;
}
void solve() {
  long long n, x;
  cin >> n >> x;
  long long sum = 0, a[n];
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  for (int i = 0; i < n; i++) {
    m[sum - a[i]]++;
  }
  long long num = LLONG_MAX, upd = 0;
  for (auto &i : m) {
    upd = i.second / x;
    i.second %= x;
    if (i.second != 0) {
      num = i.first;
      break;
    }
    if (upd > 0) m[i.first + 1] += upd;
  }
  cout << modexp(x, min(num, sum));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
