#include <bits/stdc++.h>
int a[100010];
int main() {
  int n, k, i, rec, count, flag = 1, bj, first = 1, m;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  rec = a[k - 1];
  if (n == 0) {
    printf("0");
    m = 0;
    flag = 0;
  }
  for (i = k; i < n; i++) {
    if (a[i] != rec) {
      m = 0;
      flag = 0;
      printf("-1");
      break;
    }
  }
  if (m) {
    count = 0;
    for (i = 0; i < n; i++) {
      if (a[i] != rec) {
        bj = i;
        count++;
      }
    }
    if (count == 0) {
      flag = 0;
      printf("0");
    }
  }
  if (flag) {
    printf("%d", bj + 1);
  }
}
