#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, a[100001];
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  while (a[n] == a[n - 1]) {
    n--;
  }
  if (n > k)
    cout << -1 << "\n";
  else
    cout << n - 1 << "\n";
}
