#include <bits/stdc++.h>
using namespace std;
int data[100005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  k--;
  for (int i = 0; i < n; i++) scanf("%d", &data[i]);
  bool found = true;
  for (int i = k + 1; i < n; i++)
    if (data[i] != data[k]) {
      found = false;
      break;
    }
  if (found) {
    while (k > 0 && data[k] == data[k - 1]) k--;
    printf("%d\n", k);
  } else
    printf("-1\n");
  return 0;
}
