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