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