#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[500009];
map<int, int> mapp;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  int l = 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    mapp[arr[i]]++;
    while (mapp[arr[i]] >= m) {
      ans += n - i + 1;
      mapp[arr[l++]]--;
    }
  }
  cout << ans << endl;
  return 0;
}
