#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
using str = string;
template <class T>
using V = vector<T>;
template <class T1, class T2>
using PR = pair<T1, T2>;
template <class T1, class T2>
using umap = unordered_map<T1, T2>;
using pi = PR<int, int>;
using vi = V<int>;
const ll MOD = 1e9 + 7;
ll binexp(ll a, ll b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  ll cur = binexp(a, b / 2);
  cur = cur % MOD;
  if (b % 2 == 1)
    return ((a * ((cur * cur) % MOD)) % MOD);
  else
    return ((cur * cur) % MOD);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  vi a(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += (ll)a[i];
  }
  V<ll> second(n);
  for (int i = 0; i < n; i++) second[i] = sum - (ll)a[i];
  while (true) {
    int sz = second.size();
    ll v = second[sz - 1];
    int cnt = 0;
    for (int i = sz - 1; i >= 0; i--)
      if (second[i] == v)
        cnt++;
      else
        break;
    if (cnt % x == 0) {
      int cnt2 = cnt;
      while (cnt2--) second.pop_back();
      cnt2 = cnt / x;
      while (cnt2--) second.push_back(v + 1);
    } else {
      v = min(v, sum);
      cout << binexp((ll)x, v);
      return 0;
    }
  }
}
