#include <bits/stdc++.h>
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const int pr = 49999;
const int maxn = 899821;
const int mod = (int)1e9 + 7;
const long double pi = 4 * atan(1);
const long double eps = 1e-7;
const int inf = INT_MAX;
const long long linf = LLONG_MAX;
const unsigned long long ulinf = ULLONG_MAX;
int n, k;
int a[maxn];
map<int, int> cnt;
set<int> more_k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int l = 1, r = l;
  cnt[a[r]]++;
  if (cnt[a[r]] >= k) more_k.insert(a[r]);
  bool good_break = false;
  while (r <= n) {
    if (((int)(more_k.size()))) {
      good_break = true;
      break;
    }
    if (r == n) break;
    ++r;
    cnt[a[r]]++;
    if (cnt[a[r]] >= k) more_k.insert(a[r]);
  }
  long long ans = 0;
  if (good_break)
    ans += (n - r) + 1;
  else {
    cout << 0;
    return 0;
  }
  for (int i = 2; i <= n; ++i) {
    cnt[a[l]]--;
    if (cnt[a[l]] < k && more_k.count(a[l])) more_k.erase(a[l]);
    l = i;
    if (!((int)(more_k.size()))) {
      good_break = false;
      while (r <= n) {
        if (((int)(more_k.size()))) {
          good_break = true;
          break;
        }
        if (r == n) {
          break;
        }
        ++r;
        cnt[a[r]]++;
        if (cnt[a[r]] >= k) more_k.insert(a[r]);
      }
      if (good_break) {
        ans += (n - r) + 1;
      } else {
        cout << ans;
        return 0;
      }
    } else {
      ans += (n - r) + 1;
    }
  }
  cout << ans;
  exit(0);
}
