#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10, mod = 1e9 + 7;
long long a[maxn];
long long bigmod(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long x = bigmod(a, b / 2, mod);
  x = (x * x) % mod;
  if (b & 1) x = (x * a) % mod;
  return x;
}
int main() {
  long long n, x;
  cin >> n >> x;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) cin >> a[i], sum += a[i];
  map<long long, long long> M;
  for (long long i = 1; i <= n; i++) {
    long long here = sum - a[i];
    M[here]++;
  }
  while (1) {
    auto it = *M.begin();
    if (it.second % x == 0) {
      M[it.first + 1] += it.second / x;
      M.erase(it.first);
    } else
      break;
  }
  auto p = *M.begin();
  cout << bigmod(x, min(p.first, sum), mod) << endl;
  return 0;
}
