#include <bits/stdc++.h>
using namespace std;
int num[200005], n, L;
long long ans;
namespace SGT {
int maxv[800000];
void build(int l, int r, int o) {
  if (l == r)
    maxv[o] = l;
  else {
    int m = ((l + r) >> 1);
    build(l, m, o * 2);
    build(m + 1, r, o * 2 + 1);
    maxv[o] = ((num[maxv[o * 2]] >= num[maxv[o * 2 + 1]]) ? maxv[o * 2]
                                                          : maxv[o * 2 + 1]);
  }
}
int query(int l, int r, int o, int lx, int rx) {
  if (l >= lx && r <= rx)
    return maxv[o];
  else {
    int m = ((l + r) >> 1);
    if (m >= rx) return query(l, m, o * 2, lx, rx);
    if (m < lx) return query(m + 1, r, o * 2 + 1, lx, rx);
    int a = query(l, m, o * 2, lx, rx), b = query(m + 1, r, o * 2 + 1, lx, rx);
    return (num[a] >= num[b]) ? a : b;
  }
}
}  // namespace SGT
int nxt[200005], powd[200005];
void pre() {
  static int last2[200005];
  powd[0] = 1;
  for (int i = 1; i <= n; i++)
    powd[i] = min((long long)powd[i - 1] * L, n + 1LL);
  for (int i = n; i > 0; i--) {
    nxt[i] = ((last2[num[i]]) ? last2[num[i]] : n + 1);
    last2[num[i]] = i;
  }
}
vector<int> suml[200005], sumr[200005];
vector<int> pos[200005], son[200005];
int size[200005], lsize[200005], rsize[200005];
int val[200005], tot;
void calc(int o, int d) {
  static int sum[200005];
  size[o] = ((size[o] >= powd[d]) ? size[o] / powd[d] : -1);
  if (lsize[o]) {
    for (int i = 1; i <= lsize[o]; i++) sum[i] = 0;
    int cnt = 0, maxn = 0;
    for (int i = powd[d]; i <= lsize[o]; i++) {
      maxn = i / powd[d];
      sum[maxn] += suml[o][i];
    }
    lsize[o] = maxn;
    suml[o].resize(maxn + 1);
    for (int i = 1; i <= maxn; i++) suml[o][i] = sum[i];
  }
  if (rsize[o]) {
    for (int i = 1; i <= rsize[o]; i++) sum[i] = 0;
    int cnt = 0, maxn = 0;
    for (int i = powd[d]; i <= rsize[o]; i++) {
      maxn = i / powd[d];
      sum[maxn] += sumr[o][i];
    }
    rsize[o] = maxn;
    sumr[o].resize(maxn + 1);
    for (int i = 1; i <= maxn; i++) sumr[o][i] = sum[i];
  }
}
int solve(int l, int r) {
  static int q[200005];
  int o = ++tot;
  for (int i = SGT::query(1, n, 1, l, r); i <= r; i = nxt[i])
    pos[o].push_back(i);
  val[o] = num[pos[o][0]];
  son[o].resize(pos[o].size() + 1);
  if (pos[o][0] > l) son[o][0] = solve(l, pos[o][0] - 1);
  for (int i = 1; i < pos[o].size(); i++)
    if (pos[o][i] > pos[o][i - 1] + 1)
      son[o][i] = solve(pos[o][i - 1] + 1, pos[o][i] - 1);
  if (pos[o][pos[o].size() - 1] < r)
    son[o][son[o].size() - 1] = solve(pos[o][pos[o].size() - 1] + 1, r);
  for (int i = 0; i < son[o].size(); i++)
    if (son[o][i]) calc(son[o][i], val[o] - val[son[o][i]]);
  bool v = 1;
  int sz = pos[o].size();
  for (int i = 0; i < son[o].size(); i++)
    if (size[son[o][i]] == -1)
      v = 0;
    else
      sz += size[son[o][i]];
  size[o] = ((v) ? sz : -1);
  suml[o].resize(1);
  for (int i = 0; i < son[o].size(); i++) {
    int u = son[o][i];
    for (int j = 1; j <= lsize[u]; j++) suml[o].push_back(suml[u][j]);
    if (size[u] == -1) break;
    if (i + 1 < son[o].size()) suml[o].push_back(1);
  }
  lsize[o] = suml[o].size() - 1;
  sumr[o].resize(1);
  for (int i = son[o].size() - 1; i >= 0; i--) {
    int u = son[o][i];
    for (int j = 1; j <= rsize[u]; j++) sumr[o].push_back(sumr[u][j]);
    if (size[u] == -1) break;
    if (i) sumr[o].push_back(1);
  }
  rsize[o] = sumr[o].size() - 1;
  return o;
}
int main() {
  scanf("%d%d", &n, &L);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  pre();
  SGT::build(1, n, 1);
  solve(1, n);
  printf("%lld\n", ans + n);
  return 0;
}
