#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int n, k;
vector<int> v;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  set<int> s;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
    if (i >= k) s.insert(t);
  }
  if (s.size() > 1)
    cout << -1;
  else {
    int i = k - 1;
    while (i >= 0 && v[i] == v[k - 1]) i--;
    cout << i + 1;
  }
  return 0;
}
