#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n{}, k{}, a{}, last{0}, continuous{1};
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == last) {
      continuous++;
    } else {
      continuous = 1;
    }
    last = a;
  }
  if (continuous + k > n)
    cout << n - continuous << endl;
  else
    cout << "-1\n";
  return 0;
}
