#include <bits/stdc++.h>
using namespace std;
const int MxN = 1e9;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  while (n-- && n > 0)
    if (arr[n] != arr[n - 1]) break;
  if (n >= k) {
    cout << -1;
  } else {
    cout << n;
  }
  return 0;
}
