#include <bits/stdc++.h>
using namespace std;
map<long long, long long> idx;
set<long long> s[400005];
long long a[400005];
int main() {
  long long i, j, n, m, temp, ans = 0, k, lst = 0, cnt = -1, low;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (idx.find(a[i]) == idx.end()) {
      idx[a[i]] = ++cnt;
      s[idx[a[i]]].insert(i);
    } else {
      if (s[idx[a[i]]].size() == k) s[idx[a[i]]].erase(s[idx[a[i]]].begin());
      s[idx[a[i]]].insert(i);
      if (s[idx[a[i]]].size() == k) {
        low = *(s[idx[a[i]]].begin());
        if (lst < low) {
          ans += (low - lst) * (n - i + 1);
          lst = low;
        }
      }
    }
  }
  if (k == 1) ans = (n * (n + 1)) / 2;
  cout << ans;
  return 0;
}
