#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
const int N = 1e5 + 5;
int a[N];
map<long long, int> m;
long long getAns(long long n) {
  long long x = m.begin()->first;
  while (m[x] % n == 0) {
    m[x + 1] += m[x] / n;
    x++;
  }
  return x;
}
int main() {
  int n;
  long long x, sum = 0;
  scanf("%d%I64d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    m[sum - a[i]]++;
  }
  sum = min(getAns(x), sum);
  printf("%I64d\n", powmod(x, sum, 1e9 + 7));
  return 0;
}
