#include <bits/stdc++.h>
using namespace std;
long long a[100666];
map<long long, int> fr;
long long i, x, st, numar;
long long n;
long long lgpow(long long val, long long P) {
  if (P == 1) return val;
  if (P == 0) return 1;
  long long V = lgpow(val, P / 2);
  V *= V;
  V %= 1000000007;
  if (P % 2) V *= val;
  V %= 1000000007;
  return V;
}
int main() {
  cin >> n >> x;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    st += a[i];
  }
  long long vmin = ((long long)1 << (long long)60);
  for (i = 1; i <= n; ++i) {
    long long V = st - a[i];
    fr[V]++;
    vmin = min(vmin, V);
  }
  for (i = vmin; i <= st; ++i) {
    if (fr.find(i) != fr.end()) numar += fr[i];
    if (numar % x) {
      cout << lgpow(x, i);
      return 0;
    }
    long long h = numar / x;
    fr[i + 1] += h;
  }
  cout << lgpow(x, st);
  return 0;
}
