#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int a[1000000];
int main() {
  int N, K;
  int i;
  while (scanf("%d %d", &N, &K) == 2) {
    for (i = 0; i < N; i++) {
      scanf("%d", &a[i]);
    }
    int fl = 1, res = 987654321;
    for (i = K - 1; i < N; i++) {
      if (a[K - 1] != a[i]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      res = K - 1;
      for (i = K - 2; i >= 0; i--) {
        if (a[K - 1] == a[i])
          res--;
        else
          break;
      }
      printf("%d\n", res);
    } else
      printf("-1\n");
  }
  return 0;
}
