#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k, f = 0;
    cin >> n >> k;
    vector<int> a(n);
    set<int> s;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s.insert(a[i]);
    }
    if (s.size() == 1) {
      cout << 0;
      return 0;
    }
    for (int i = k - 1; i < n - 1; i++) {
      if (a[i] != a[i + 1]) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      int p = k - 2;
      while (a[p] == a[k - 1] && p > 0) p--;
      cout << p + 1;
    } else
      cout << -1;
  }
}
