#include <bits/stdc++.h>
using namespace std;
int strToInt(string str) {
  int ans;
  stringstream s;
  s << str;
  s >> ans;
  return ans;
}
string intToStr(int n) {
  string str;
  stringstream s;
  s << n;
  s >> str;
  return str;
}
int MAX(int a, int b) {
  if (a > b) return a;
  return b;
}
int MIN(int a, int b) {
  if (a < b) return a;
  return b;
}
int ABS(int a, int b) {
  if (a > 0) return a;
  return -a;
}
int main() {
  int n, k;
  cin >> n >> k;
  int arr[100010];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int i;
  for (i = (k); i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      printf("-1\n");
      break;
    }
  }
  if (i == n) {
    int index = k - 2;
    while (index >= 0 && (arr[index] == arr[index + 1])) index--, k--;
    printf("%d\n", (k - 1));
  }
  return 0;
}
