#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long eq = a[k - 1];
  for (long long i = k; i < n; i++) {
    if (a[i] != eq) {
      cout << "-1\n";
      return;
    }
  }
  long long i = k - 2, cnt = 0;
  while (i >= 0 && a[i] == eq) {
    cnt++;
    i--;
  }
  long long ans = k - 1 - cnt;
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
