#include <bits/stdc++.h>
using namespace std;
int ara[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  int val = 1;
  for (int i = k + 1; i <= n; i++) {
    if (ara[i] == ara[i - 1])
      ;
    else
      val = 0;
  }
  if (val == 0) {
    cout << -1;
    return 0;
  }
  int num = ara[k];
  int pos = k;
  for (int i = k - 1; i >= 1; i--) {
    if (ara[i] == num)
      pos--;
    else
      break;
  }
  cout << pos - 1;
}
