#include <bits/stdc++.h>
using namespace std;
int max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void swap(int* pa, int* pb) {
  int t = *pa;
  *pa = *pb;
  *pb = t;
}
map<int, int> b;
int n, k;
vector<int> a;
int anc;
bool check() {
  for (auto now : a) {
    if (b[now] == k) {
      anc = now;
      return 1;
    }
  }
  anc = 0;
  return 0;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  bool ind = 0;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]] = 0;
  }
  long long ans = 0;
  int j = 0;
  for (int i = 0; i <= n - k; i++) {
    while (j < n && (*b.find(a[j])).second != k - 1) {
      b[a[j]]++;
      j++;
    }
    if (j == n) {
      cout << ans;
      return 0;
    }
    ans += n - j;
    b[a[i]]--;
  }
  cout << ans;
  return 0;
}
