#include <iostream>
using namespace std;
int main()
{
	int n, k, i, j=0, d=0, wynik=0; //d-liczy ile jest już ułożonych spoko
	cin>>n>>k;
	int t[n], xd[k]; //t-podstawowa tablica
	bool bylo[n+1], c=true; //bylo-było i tyle
	for (i=0; i<n; i++)
	{
		cin>>t[i];
		bylo[i]=0;
		if (i<k) xd[i]=0;
	}
	bylo[n]=false;
	bylo[t[0]]=true;
	for (i=1; i<k; i++)
	{
		if (bylo[t[i]]==false) 
		{
			d++;
			bylo[t[i]]=true;
		}
		else break;
	}
	if (d+1<k)
	{
		for (i=d+1; i<n; i++)
		{
			if (bylo[t[i]]==0)
			{
				bylo[t[i]]=1;
				xd[j]=i;
				j++;
			}
		}
		for (i=0; i<j; i++)
		{
			wynik=wynik+xd[i]-d-i-1;
		}
		if (wynik>0) cout<<wynik;
		else cout<<-1;
	}
	else
	{
		cout<<"0";
	}
}
