#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long n, x, m, sum, mn;
long long a[N];
long long b[N];
long long cnt[N];
long long pw(long long k) {
  if (k == 0) return 1;
  long long tmp = pw(k / 2);
  tmp = tmp * tmp % mod;
  if (k % 2) return tmp * x % mod;
  return tmp;
}
signed main() {
  cin >> n >> x;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  b[m] = -1;
  for (long long i = 1; i <= n; i++) {
    if (a[i] != b[m]) b[++m] = a[i];
    cnt[m]++;
  }
  mn = 1e18;
  for (long long i = 1; i <= m; i++) {
    b[i] = sum - b[i];
  }
  for (long long i = m; i >= 1; i--) {
    while (cnt[i] % x == 0) {
      cnt[i] /= x;
      b[i]++;
      if (b[i] == b[i - 1]) {
        cnt[i - 1] += cnt[i];
        cnt[i] = 0;
        break;
      }
    }
    if (cnt[i]) {
      mn = b[i];
      break;
    }
  }
  cout << pw(min(mn, sum));
  return 0;
}
