n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
r = -1
cnt = {}
for l in range(n):
while r < n and len(cnt) < k:
r += 1
if r == n:
break
cnt[a[r]] = cnt.get(a[r], 0) + 1
ans += n - r
cnt[a[l]] -= 1
if cnt[a[l]] == 0:
del cnt[a[l]]
print(ans)