#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n;
long long x;
long long a[100050];
long long ans;
long long sum = 0, lastsum = 0, nowsum = 0;
long long pow(long long x, long long y) {
  long long temp = 1;
  while (y) {
    if (y & 1) {
      temp *= x;
      temp %= mod;
    }
    x *= x;
    x %= mod;
    y >>= 1;
  }
  return temp % mod;
}
int main() {
  scanf("%d%lld", &n, &x);
  sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  lastsum = sum;
  sum -= a[n];
  long long now = 0;
  long long temp = a[n];
  a[0] = INT_MIN;
  for (int i = n; i >= 0; i--) {
    if (temp == a[i]) {
      now++;
    } else {
      if (now % x == 0) {
        temp = a[i];
        while ((nowsum < a[i + 1] - a[i] || i == 0) && now % x == 0) {
          now /= x;
          nowsum++;
        }
        sum += nowsum;
        if (a[i + 1] != a[i] + nowsum) break;
        now++;
        nowsum = 0;
      } else {
        break;
      }
    }
  }
  ans = pow(x, min(sum, lastsum));
  printf("%lld\n", ans);
  return 0;
}
