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