#include <bits/stdc++.h>
using namespace std;
map<int, int> tree;
map<int, int>::iterator iter;
int n, x, a;
long long sum = 0;
long long mod = 1000000007;
long long po(long long a, long long s) {
  if (s == 0) return 1;
  if (s & 1)
    return po(a * a % mod, s >> 1) * a % mod;
  else
    return po(a * a % mod, s >> 1);
}
void in(int s) {
  iter = tree.find(s);
  if (iter == tree.end()) {
    tree.insert(make_pair(s, 1));
  } else {
    iter->second++;
    if (iter->second == x) {
      tree.erase(iter);
      in(s + 1);
    }
  }
}
int main() {
  tree.clear();
  scanf("%d%d", &n, &x);
  for (int q = 0; q < n; q++) {
    scanf("%d", &a);
    sum += a;
    in(-a);
  }
  iter = tree.begin();
  cout << po(x, min(sum + iter->first, sum)) << endl;
  return 0;
}
