#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long llinf = 1e18 + 7;
const double eps = 1e-15;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  int n, a[100001], k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int i = n;
  while (i > 0 && a[n] == a[i]) i--;
  if (i >= k)
    cout << -1;
  else
    cout << i;
  return 0;
}
