#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  v.push_back(-1000);
  for (int i = 1; i <= n; i++) {
    int b;
    cin >> b;
    v.push_back(b);
  }
  set<int> s;
  set<int>::iterator it;
  for (int i = v.size() - 1; i > 0; i--) {
    s.insert(v[i]);
    if (i == k) {
      if (s.size() == 1) {
        for (it = s.begin(); it != s.end(); it++) {
          if (*it != v[k]) {
            cout << -1 << endl;
            return 0;
          }
        }
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = k - 1; i > 0; i--) {
    if (v[k] != v[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
