#include <bits/stdc++.h>
using namespace std;
unsigned long long fp(unsigned long long a, unsigned long long b) {
  if (!b) return 1;
  unsigned long long u = fp(a, b / 2);
  unsigned long long r = ((u % 1000000007) * (u % 1000000007)) % 1000000007;
  if (b % 2 == 0) return r;
  return (r * a % 1000000007) % 1000000007;
}
map<long long, long long> freq;
long long start = 1e18, sum;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x, cnt = 0, sub = 0;
  cin >> n >> x;
  long long arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i], sum += arr[i];
  for (int i = 0; i < n; i++)
    freq[sum - arr[i]]++, (start = min(start, sum - arr[i]));
  cnt += start;
  if (freq[start] % x != 0) goto go;
  sub += start;
  freq[1] = freq[start] / x + freq[sub + 1];
  while (1) {
    cnt++;
    sub++;
    if (freq[1] % x != 0) break;
    freq[1] = freq[1] / x + freq[sub + 1];
  }
go:;
  cout << fp(x, min(sum, cnt));
  return 0;
}
