#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long pw(long long b, long long p) {
  if (!p) return 1;
  if (p == 1) return b;
  if (p % 2) return (b * pw((b * b) % mod, (p - 1) / 2) % mod) % mod;
  return pw((b * b) % mod, p / 2) % mod;
}
int main() {
  long long n, x;
  while (cin >> n >> x) {
    vector<long long> a(n);
    for (int i = 0; i < n; scanf("%I64d", &a[i++]))
      ;
    long long sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    for (int i = 0; i < n; i++) a[i] = sum - a[i];
    sort(a.rbegin(), a.rend());
    long long res = -1;
    while (res == -1) {
      long long tmp = a.back(), cnt = 0;
      while (a.size() && a.back() == tmp) a.pop_back(), cnt++;
      if (cnt % x == 0)
        for (int i = 0; i < cnt / x; i++) a.push_back(tmp + 1);
      else
        res = pw(x, min(sum, tmp));
    }
    cout << res << endl;
  }
  return 0;
}
