#include <bits/stdc++.h>
using namespace std;
long long first, sum, k, ans, a[100005];
vector<int> v;
map<long long, long long> m;
map<long long, long long>::iterator ii;
long long func(long long k) {
  if (k == 0) return 1;
  long long t = func(k / 2);
  t = t * t % 1000000007;
  if (k & 1) t = t * first % 1000000007;
  return t % 1000000007;
}
int main() {
  int n;
  cin >> n >> first;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans = ans + a[i];
  }
  for (int i = 0; i < n; ++i) m[ans - a[i]]++;
  for (ii = m.begin(); ii != m.end(); ++ii) {
    if (ii->second >= first) {
      k = ii->second / first;
      ii->second %= first;
      m[ii->first + 1] += k;
    }
    if (ii->second) {
      ans = min(ans, ii->first);
      break;
    }
  }
  cout << func(ans);
  return 0;
}
