#include <bits/stdc++.h>
using namespace std;
int x[100000];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  for (int i = k--; i < n; i++)
    if (x[i] != x[k]) {
      cout << "-1" << endl;
      return 0;
    }
  for (int i = k - 1; i >= 0; i--)
    if (x[i] != x[k]) {
      cout << i + 1 << endl;
      return 0;
    }
  cout << 0 << endl;
}
