#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
int n, k;
vector<int> a;
bool isTrue;
void add(int u) {
  cnt[u]++;
  if (cnt[u] == k) isTrue = true;
}
void remv(int u) {
  cnt[u]--;
  if (cnt[u] == k - 1) isTrue = false;
}
int main() {
  cin >> n >> k;
  a.assign(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  int l = 0, r = 0;
  long long res = 0;
  isTrue = false;
  while (r < n) {
    while (!isTrue && r < n) {
      add(a[r]);
      r++;
    }
    if (isTrue) {
      res += (n - r + 1);
    }
    remv(a[l]);
    l++;
  }
  while (isTrue && l < n) {
    if (isTrue) res++;
    remv(a[l]);
    l++;
  }
  cout << res << endl;
  return 0;
}
