#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= (n); ++i) {
    cin >> a[i];
  }
  int temp = a[k];
  for (int i = k; i <= n; i++) {
    if (a[i] != temp) {
      cout << -1 << endl;
      return 0;
    }
  }
  int res = 0;
  for (int i = 1; i <= (k); ++i) {
    if (a[i] != temp) {
      res = i;
    }
  }
  cout << res << endl;
  return 0;
}
