#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, n;
  cin >> n >> k;
  int ara[n], i;
  for (i = 0; i < n; i++) cin >> ara[i];
  int digit = ara[k - 1];
  for (i = k; i < n; i++) {
    if (ara[i] != digit) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (i = k - 2; i >= 0; i--) {
    if (ara[i] != digit) break;
  }
  cout << i + 1 << endl;
  return 0;
}
