#include <bits/stdc++.h>
using namespace std;
long long const MX = 4e5 + 10;
long long const INF = 1e9;
long long arr[MX];
map<long long, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int i = 1, j = 1;
  long long res = 0;
  for (i; i < k; i++) mp[arr[i]]++;
  while (i <= n) {
    mp[arr[i]]++;
    if (mp[arr[i]] >= k) {
      while (mp[arr[i]] >= k && j <= n) {
        res += (n - i + 1);
        mp[arr[j]]--;
        j++;
      }
    }
    i++;
  }
  cout << res;
  return 0;
}
