#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  k--;
  vector<int> arr(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int gold = arr[k];
  for (int i = k; i < arr.size(); i++) {
    if (arr[i] != gold) {
      cout << "-1";
      return 0;
    }
  }
  for (int i = k; i >= 0; i--) {
    if (arr[i] != gold) {
      cout << i + 1;
      return 0;
    }
  }
  cout << "0";
  return 0;
}
