#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 256;
int n, a[MAXN], k, ans;
list<int> L;
set<int> s, S;
multiset<int> M;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i >= k) s.insert(a[i]);
  }
  if (s.size() > 1) {
    cout << -1;
    return 0;
  }
  ans = k - 1;
  while (a[ans] == a[k]) --ans;
  cout << ans;
  return 0;
}
