#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;
long long n, x;
long long sum;
long long arr[MAXN];
vector<long long> comb;
template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
class Node {
 public:
  long long val, num;
  Node(long long v, long long n) {
    val = v;
    num = n;
  }
};
vector<Node> nodes;
long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long getCoef(long long x, long long n) {
  long long mul = x;
  long long num = 1;
  while (n % mul == 0) {
    mul *= x;
    num++;
  }
  return num - 1;
}
int main() {
  while (scanf("%I64d %I64d", &n, &x) != -1) {
    sum = 0;
    for (int i = (0); i < (n); i += 1) {
      scanf("%I64d", &arr[i]);
      sum += arr[i];
    }
    nodes.clear();
    int idx = 0;
    while (idx < n) {
      int next = idx + 1;
      while (next < n && arr[next] == arr[idx]) {
        next++;
      }
      long long val = sum - arr[idx];
      nodes.push_back(Node(val, next - idx));
      idx = next;
    }
    for (idx = nodes.size() - 1; idx > 0;) {
      if (nodes[idx].num % x != 0) {
        break;
      } else {
        if (nodes[idx - 1].val == nodes[idx].val + 1) {
          nodes[idx - 1].num += nodes[idx].num / x;
          nodes.pop_back();
          idx--;
        } else {
          nodes[idx].num /= x;
          nodes[idx].val++;
        }
      }
    }
    long long coef = getCoef(x, nodes[idx].num);
    long long least = min(sum, coef + nodes[idx].val);
    long long res = mod_pow(x, least, 1000000007);
    printf("%I64d\n", res);
  }
  return 0;
}
