#include <bits/stdc++.h>
using namespace std;
long long int a, b, n, m, k, p, x, cont = 0, t = -1000000;
int main() {
  cin >> n >> k;
  long long int q[n];
  for (a = 0; a < n; a++) {
    cin >> q[a];
    x = q[a];
    if (x != t) {
      t = x;
      cont++;
    }
  }
  if (cont <= 1) {
    cout << "0";
    return 0;
  }
  for (b = k - 1; b < n; b++) {
    if (q[b] != q[k - 1]) {
      cout << "-1";
      return 0;
    }
  }
  for (m = 0; m < k; m++) {
    if (q[m] != q[k - 1]) p = m;
  }
  cout << p + 1;
  return 0;
}
