#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int prev;
  int a[n];
  cin >> a[0];
  prev = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (i > k - 1) {
      if (prev != a[i]) {
        cout << -1;
        return 0;
      }
    }
    prev = a[i];
  }
  int index;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if ((prev == a[i]) && !flag) {
      index = i;
      flag = !flag;
    }
    if ((prev != a[i]) && flag) {
      flag = !flag;
    }
  }
  cout << index;
  return 0;
}
