#include <bits/stdc++.h>
int main() {
  int n, k, arr[100000], flag = 0, i;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  if (n == 1) {
    if (n == k)
      printf("0");
    else
      printf("-1");
  } else if (k == n) {
    int count = 0;
    for (i = 0; i < n - 1; i++)
      if (arr[i] == arr[k - 1]) count++;
    printf("%d", k - 1 - count);
  } else {
    int count = 0, count1 = 0;
    for (i = k; i < n; i++)
      if (arr[k - 1] == arr[i]) count1++;
    for (i = k - 1; i > 0; i--) {
      if (arr[i] == arr[i - 1])
        count++;
      else
        break;
    }
    if (count1 == n - k)
      printf("%d", k - 1 - count);
    else
      printf("-1");
  }
  return 0;
}
