#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int n, k, a[MAXN];
int cnt[MAXN], now;
inline void add(int x) {
  cnt[x]++;
  if (cnt[x] == 1) now++;
}
inline void del(int x) {
  cnt[x]--;
  if (cnt[x] == 0) now--;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  bool flag = 1;
  for (int i = k + 1; i <= n; ++i) flag &= (a[i] == a[i - 1]);
  if (!flag) {
    puts("-1");
    return 0;
  }
  for (int i = k - 1; i >= 0; --i) {
    if (a[i] != a[k]) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}
