#include <bits/stdc++.h>
using namespace std;
long long int power(long long int base, long long int exp) {
  long long int res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = ((res % 1000000007) * (base % 1000000007));
    base = ((base % 1000000007) * (base % 1000000007));
    exp /= 2;
  }
  return res % 1000000007;
}
void solve() {
  long long int n, x, i, j;
  cin >> n >> x;
  long long int a[n];
  long long int mx = 0, ind = -1, cnt = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) {
      mx = a[i];
      ind = i;
      cnt = 1;
    } else if (a[i] == mx)
      cnt++;
  }
  long long int ans = 1;
  for (i = 0; i < n; i++) {
    if (i != ind) ans = ans * power(x, a[i]);
    ans %= 1000000007;
  }
  map<long long int, long long int> m;
  for (i = 0; i < n; i++) {
    a[i] = mx - a[i];
    m[a[i]]++;
  }
  long long int p = 0;
  while (m[p] % x == 0 && p < mx) {
    m[p + 1] += m[p] / x;
    p++;
  }
  ans *= power(x, p);
  ans %= 1000000007;
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
