#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.in");
vector<int> V[400005];
map<int, int> MP;
pair<pair<int, int>, int> T[2000000];
int N, K, n, B, S, M;
void read() {
  int s, t;
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &s);
    t = MP[s];
    if (t)
      V[t].push_back(i);
    else {
      MP[s] = ++n;
      V[n].push_back(0), V[n].push_back(i);
    }
  }
}
void tree() {
  int t, mx = 1;
  T[1] = make_pair(make_pair(1, N), 0);
  for (int i = 1; i <= mx; i++) {
    if (T[i].first.first == T[i].first.second) continue;
    t = (T[i].first.first + T[i].first.second) / 2;
    T[2 * i] = make_pair(make_pair(T[i].first.first, t), 0);
    T[2 * i + 1] = make_pair(make_pair(t + 1, T[i].first.second), 0);
    mx = 2 * i + 1;
  }
}
void mark(int nod) {
  int first = T[nod].first.first, second = T[nod].first.second;
  if (B > second || S < first) return;
  if (B <= first && S >= second)
    T[nod].second = ((M) > (T[nod].second) ? (M) : (T[nod].second));
  else {
    mark(2 * nod);
    mark(2 * nod + 1);
  }
}
long long int bul(int s, int nod) {
  int first = T[nod].first.first, second = T[nod].first.second;
  if (s < first || s > second) return 0;
  return ((T[nod].second) > (((bul(s, 2 * nod)) > (bul(s, 2 * nod + 1))
                                  ? (bul(s, 2 * nod))
                                  : (bul(s, 2 * nod + 1))))
              ? (T[nod].second)
              : (((bul(s, 2 * nod)) > (bul(s, 2 * nod + 1))
                      ? (bul(s, 2 * nod))
                      : (bul(s, 2 * nod + 1)))));
}
void solve() {
  long long int res = 0, t;
  int i, j;
  tree();
  for (i = 1; i <= n; i++)
    for (j = 1; j + K - 1 < V[i].size(); j++) {
      B = V[i][j - 1] + 1;
      S = V[i][j];
      M = N - V[i][j + K - 1] + 1;
      mark(1);
    }
  for (i = 1; i <= N; i++) res += bul(i, 1);
  printf("%I64d\n", res);
}
int main() {
  read();
  solve();
}
