#include <bits/stdc++.h>
using namespace std;
int n, k, i, a[100005];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  while (a[n] == a[n - 1]) n--;
  if (k < n)
    cout << -1;
  else
    cout << n - 1;
  return 0;
}
