#include <bits/stdc++.h>
using namespace std;
map<int, int> c;
int a[400001];
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    c[a[i]] = 0;
  }
  int l = 1, r = 1;
  long long ans = 0;
  while (r <= n) {
    ++c[a[r]];
    while ((l <= r) && (c[a[r]] >= m)) {
      ans += n - r + 1;
      --c[a[l]];
      ++l;
    }
    ++r;
  }
  printf("%I64d\n", ans);
  return 0;
}
