#include <bits/stdc++.h>
using namespace std;
long long A[100008];
map<long long, long long> mymap;
long long pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
int main() {
  long long n, x;
  long long ans, total = 0;
  scanf("%lld", &n);
  scanf("%lld", &x);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &A[i]);
    total += A[i];
  }
  for (int i = 0; i < n; i++) {
    A[i] = total - A[i];
    mymap[A[i]]++;
  }
  for (typeof((mymap).begin()) it = (mymap).begin(); it != (mymap).end();
       it++) {
    if (it->second / x != 0) {
      mymap[it->first + 1] += it->second / x;
    }
    mymap[it->first] = it->second % x;
    if (mymap[it->first] != 0) {
      ans = it->first;
      break;
    }
  }
  ans = pow(x, min(ans, total));
  printf("%lld\n", ans);
  ;
  return 0;
}
