#include <bits/stdc++.h>
using namespace std;
long long fast_pow(long long a, long long k) {
  if (k == 0ll)
    return 1ll;
  else if (k == 1ll)
    return a;
  else if (!(k & 1ll)) {
    long long aux = fast_pow(a, k / 2) % 1000000007;
    return (aux * aux) % 1000000007;
  } else
    return (a * fast_pow(a, k - 1) % 1000000007) % 1000000007;
}
long long arr[100100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x;
  cin >> n >> x;
  long long sum = 0ll;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  map<long long, long long> freq;
  for (int i = 0; i < n; i++) freq[sum - arr[i]]++;
  for (auto e : freq) {
    if (e.second % x == 0)
      freq[e.first + 1] += e.second / x;
    else {
      if (e.first > sum)
        cout << fast_pow(x, sum) << "\n";
      else
        cout << fast_pow(x, e.first) << "\n";
      break;
    }
  }
  return 0;
}
