#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
const long long MOD = 1000000007;
long long bpow(long long x, long long v) {
  if (v == 0) return 1 % MOD;
  if (v % 2 == 1) return (x * bpow(x, v - 1)) % MOD;
  long long r = bpow(x, v / 2);
  return (r * r) % MOD;
}
int main() {
  long long x, n;
  long long sum = 0;
  long long max1 = -1;
  int k = 1;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    long long c;
    cin >> c;
    sum += c;
    a.push_back(c);
  }
  sort(a.begin(), a.end());
  while (true) {
    long long v = a[a.size() - 1];
    int counter = 0;
    while (a.size() > 0 && a.back() == v) {
      counter++;
      a.pop_back();
    }
    if (counter % x != 0) {
      if (v <= 0) {
        v = 0;
      }
      cout << bpow(x, sum - v);
      return 0;
    } else {
      counter = counter / x;
      for (int i = 0; i < counter; i++) {
        a.push_back(v - 1);
      }
    }
  }
  return 0;
}
