#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  int count = 0;
  bool check = false;
  cin >> n >> k;
  int ans[100001];
  for (int i = 0; i < n; i++) {
    cin >> ans[i + 1];
  }
  for (int i = k; i < n; i++) {
    if (ans[i] != ans[i + 1]) check = true;
  }
  if (check == false) {
    for (int i = k - 1; i >= 1; i--) {
      if (ans[i] != ans[k]) {
        count = i;
        break;
      }
    }
    cout << count << endl;
  } else
    cout << -1 << endl;
  return 0;
}
