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