#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  map<long long, long long> m1;
  long long start = 0, end = 0, s = 0;
  while (end < n) {
    m1[a[end]]++;
    while (m1[a[end]] >= m) {
      s += (n - end);
      m1[a[start]]--;
      start++;
    }
    end++;
  }
  cout << s << "\n";
}
