#include <bits/stdc++.h>
using namespace std;
long long a[111111];
long long gao(long long x, long long m) {
  long long ans = 1;
  while (m) {
    if (m & 1) ans *= x, ans %= 1000000007;
    m >>= 1;
    x = x * x;
    x %= 1000000007;
  }
  return ans;
}
long long x;
int n;
int main() {
  while (cin >> n >> x) {
    long long s = 0;
    for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
    long long ans = s - a[n - 1];
    int p = n - 1;
    long long cnt = 0;
    for (long long m = a[n - 1]; m; m--) {
      while (p >= 0 && a[p] == m) p--, cnt++;
      if (cnt % x) break;
      cnt /= x;
      ans++;
    }
    cout << gao(x, ans) % 1000000007 << endl;
  }
  return 0;
}
