#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  int ans = -1;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = k; i < n + 1; i++) {
    if (a[k] != a[i]) {
      cout << ans << endl;
      return;
    }
  }
  int i = k;
  while (a[k] == a[i] && i > 0) {
    i--;
  }
  cout << i << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
