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