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