#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n = 0, k = 0;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool can = 1;
  for (int i = k; i < n; i++) {
    if (a[i] != a[i - 1]) can = 0;
  }
  int i;
  for (i = n - 1; i >= 1; i--) {
    if (a[i] != a[i - 1]) {
      break;
    }
  }
  if (can)
    cout << i << "\n";
  else
    cout << -1 << "\n";
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
