#include <bits/stdc++.h>
int niz[100100];
int main() {
  int i, j, x, y, n, m;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &niz[i]);
  int ok = 1;
  for (i = m + 1; i <= n; i++)
    if (niz[i] != niz[m]) {
      ok = 0;
      break;
    }
  if (!ok) {
    printf("-1\n");
    return 0;
  }
  while (niz[m - 1] == niz[m]) m--;
  printf("%d\n", m - 1);
  return 0;
}
