#include <bits/stdc++.h>
using namespace std;
long long po(long long x, long long sum, long long mod) {
  long long ans;
  if (sum == 0)
    return 1;
  else if (sum == 1)
    return x;
  else {
    long long temp;
    temp = po(x, sum / 2, mod);
    if (sum % 2 == 1) {
      ans = (temp * temp) % mod;
      ans *= x;
      ans %= mod;
      return ans;
    } else {
      ans = (temp * temp) % mod;
      return ans;
    }
  }
}
long long gcd(long long a, long long b) {
  long long t;
  if (a < b) {
    t = a;
    a = b;
    b = t;
  }
  t = (a % b);
  while (t != 0) {
    a = b;
    b = t;
    t = (a % b);
  }
  return b;
}
bool compare(int a, int b) { return (a < b); }
int main() {
  long long n, x, i, j, k, sum = 0, max = 0, ans, temp = 0;
  long long *a, *b;
  a = (long long *)malloc(100001 * sizeof(long long));
  b = (long long *)malloc(100001 * sizeof(long long));
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (max < a[i]) max = a[i];
  }
  sum -= max;
  ans = po(x, sum, 1000000007);
  for (i = 0; i < n; i++) {
    b[i] = max - a[i];
  }
  long long c1, c2;
  sort(b, b + n, compare);
  c1 = 0;
  i = 0;
  temp = 0;
  while (i < n) {
    while ((i < n) && (b[i] - temp == 0)) {
      c1++;
      i++;
    }
    if (c1 % x == 0) {
      if (max > 0) {
        c1 /= x;
        temp++;
        ans *= x;
        ans %= 1000000007;
        max--;
      } else
        break;
    } else {
      break;
    }
  }
  while ((c1 % x == 0) && (max > 0)) {
    c1 /= x;
    temp++;
    ans *= x;
    ans %= 1000000007;
    max--;
  }
  cout << ans << endl;
  return 0;
}
