#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 200005;
int n, L;
int a[N];
int rp[N];
vector<int> vl[N], vr[N];
bool cmp(int x, int y) {
  if (a[x] != a[y]) return a[x] < a[y];
  return x < y;
}
vector<int> pos[N], v, v2, tl, tr;
int vis[N];
int main() {
  n = read(), L = read();
  for (int i = (1); i <= (n); i++) {
    a[i] = read();
    if (a[i] <= n) pos[a[i]].push_back(i);
  }
  long long ans = n;
  for (int k = (1); k <= (n); k++) {
    for (auto i : pos[k]) {
      rp[i] = i;
      vl[i].push_back(1), vr[i].push_back(1);
      v.push_back(i);
    }
    if (v.empty()) continue;
    sort(v.begin(), v.end());
    for (int i = (1); i <= ((int)v.size() - 1); i++) assert(v[i] != v[i - 1]);
    int las = v[0];
    v2.clear();
    tl.clear(), tr.clear();
    tr.push_back(0);
    for (int _ = (0); _ <= ((int)v.size() - 1); _++) {
      int i = v[_];
      for (int j = (0); j <= ((int)vl[i].size() - 1); j++) {
        ans += (long long)vl[i][j] *
               tr[max((int)tr.size() - max(L - (j + 1), 1), 0)];
        if (j < (int)vl[i].size() - 1)
          tl.push_back(vl[i][j] - vl[i][j + 1]);
        else
          tl.push_back(vl[i][j]);
      }
      int tmp = tr.back();
      for (int j = ((int)vr[i].size() - 1); j >= (0); j--)
        tr.push_back(vr[i][j] + tmp);
      if (_ == (int)v.size() - 1 || v[_ + 1] != rp[i] + 1) {
        rp[las] = rp[i];
        for (int i = ((int)tr.size() - 1); i >= (1); i--) tr[i] -= tr[i - 1];
        vl[las] = tl;
        vr[las].clear();
        for (int i = ((int)tr.size() - 1); i >= (1); i--)
          vr[las].push_back(tr[i]);
        for (int i = (0); i <= ((int)vl[las].size() - 1); i++)
          vl[las][(i + 1) / L] += vl[las][i], vl[las][i] = 0;
        vl[las][0] = 0;
        for (int i = (0); i <= ((int)vl[las].size() - 2); i++)
          vl[las][i] = vl[las][i + 1], vl[las][i + 1] = 0;
        while (!vl[las].empty() && !vl[las].back()) vl[las].pop_back();
        for (int i = ((int)vl[las].size() - 1); i >= (1); i--)
          vl[las][i - 1] += vl[las][i];
        for (int i = (0); i <= ((int)vr[las].size() - 1); i++)
          vr[las][(i + 1) / L] += vr[las][i], vr[las][i] = 0;
        vr[las][0] = 0;
        for (int i = (0); i <= ((int)vr[las].size() - 2); i++)
          vr[las][i] = vr[las][i + 1], vr[las][i + 1] = 0;
        while (!vr[las].empty() && !vr[las].back()) vr[las].pop_back();
        for (int i = ((int)vr[las].size() - 1); i >= (1); i--)
          vr[las][i - 1] += vr[las][i];
        if (!vl[las].empty()) v2.push_back(las);
        if (_ != (int)v.size() - 1) {
          las = v[_ + 1];
          tl.clear(), tr.clear();
          tr.push_back(0);
        }
      }
    }
    v = v2;
  }
  cout << ans << endl;
  return 0;
}
