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