#include <bits/stdc++.h>
using namespace std;
int n, k, a[100005];
int main() {
  while (~scanf("%d%d", &n, &k)) {
    int i, j;
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    int ans = -1;
    a[0] = -11111;
    for (i = n; i >= 1; i--) {
      if (a[i] != a[i - 1]) {
        ans = i - 1;
        break;
      }
    }
    if (ans >= k) {
      printf("-1\n");
    } else {
      printf("%d\n", ans);
    }
  }
  return 0;
}
