#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 10;
int n, k, a[MAX_N];
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i + 1]);
  }
  bool bRet = true;
  for (int i = k; i <= n; i++)
    if (a[i] != a[k]) {
      bRet = false;
    }
  if (!bRet) {
    printf("-1\n");
    return 0;
  }
  for (; (k > 1) && (a[k] == a[k - 1]); k--)
    ;
  printf("%d\n", k - 1);
  return 0;
}
