#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n, k;
int a[200000];
bool ok() {
  int cur = a[k - 1];
  for (int i = k; i < n; ++i) {
    if (a[i] != cur) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  if (!ok())
    cout << -1 << endl;
  else {
    int ans = 0;
    int cur = a[k - 1];
    for (int i = 0; i < (int)(k); i++) {
      if (a[i] != cur) ans = i + 1;
    }
    cout << ans << endl;
  }
  return 0;
}
