#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10, mod = 1e9 + 7;
long long fastpow(long long b, long long p) {
  if (p == 0) return 1;
  long long x = fastpow(b, p / 2);
  x = (x * x) % mod;
  if (p % 2) x = (x * b) % mod;
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c = 1;
  long long x, y, sum = 0;
  cin >> n >> x;
  vector<long long> v, a(n);
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  for (int i = 0; i < n; i++) v.push_back(sum - a[i]);
  sort(v.rbegin(), v.rend());
  while (c != 0) {
    y = v.back();
    c = 0;
    while (!v.empty() && y == v.back()) v.pop_back(), c++;
    if (c % x)
      return cout << fastpow(x, min(y, sum)), 0;
    else {
      c /= x;
      for (int i = 0; i < c; i++) v.push_back(y + 1);
    }
  }
  return 0;
}
