#include <iostream>

using namespace std;

int n, k, a[100005];

int main(){
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int t = a[n];
	int z = 0;
	for (int i = n-1; i >= 1; i--){
		if (a[i]!=t){
			z = i;
			//cout << t << endl;
			break;
		}
	}
	if (k>z) cout << z;
	else cout << -1;
	return 0;
}