#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,ans=0,dem=0;
map<int,int>p;
signed main()
{
cin>>n>>m;
int a[n+1];
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for (int l=1,r=1;r<=n;r++)
{
if (p[a[r]]==0)
{
dem++;
p[a[r]]=1;
}
else p[a[r]]++;
while (dem>m)
{
p[a[l]]--;
if (p[a[l]]==0)
{
dem--;
}
l++;
}
ans+=r-l+1;
}
cout<<ans;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLG0sYW5zPTAsZGVtPTA7Cm1hcDxpbnQsaW50PnA7CnNpZ25lZCBtYWluKCkKewogICAgY2luPj5uPj5tOwogICAgaW50IGFbbisxXTsKICAgIGZvciAoaW50IGk9MTtpPD1uO2krKykKICAgIHsKICAgICAgICBjaW4+PmFbaV07CiAgICB9CiAgICBmb3IgKGludCBsPTEscj0xO3I8PW47cisrKQogICAgewogICAgICAgIGlmIChwW2Fbcl1dPT0wKQogICAgICAgIHsKICAgICAgICAgICAgZGVtKys7CiAgICAgICAgICAgIHBbYVtyXV09MTsKICAgICAgICB9CiAgICAgICAgZWxzZSBwW2Fbcl1dKys7CiAgICAgICAgd2hpbGUgKGRlbT5tKQogICAgICAgIHsKICAgICAgICAgICAgcFthW2xdXS0tOwogICAgICAgICAgICBpZiAocFthW2xdXT09MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZGVtLS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbCsrOwogICAgICAgIH0KICAgICAgICBhbnMrPXItbCsxOwogICAgfQogICAgY291dDw8YW5zOwp9