#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
set<int> s;
int main() {
  int n, k, i;
  cin >> n >> k;
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  for (i = k; i < n; i++) {
    if (a[i] == a[i + 1]) cnt++;
  }
  if (cnt == n - k) {
    int ans = k - 1;
    for (ans = k - 1; ans >= 1; ans--) {
      if (a[ans] != a[k]) break;
    }
    cout << ans << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
