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