#include <bits/stdc++.h>
using namespace std;
int MAX = 1e9;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for (auto &it : x) {
    cin >> it;
  }
  bool mark = 0;
  for (int i = k - 1; i < n - 1; i++) {
    if (x[i] != x[i + 1]) mark = 1;
  }
  int ans = 0;
  if (mark)
    cout << "-1\n";
  else {
    for (int i = k - 2; i >= 0; i--) {
      if (x[i] == x[k - 1])
        ans++;
      else
        break;
    }
    ans = k - ans - 1;
    cout << ans << "\n";
  }
  return 0;
}
