#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int num = v[k - 1];
  bool flag = true;
  for (int i = k; i <= n - 1; i++) {
    if (v[i] == num)
      continue;
    else
      flag = false;
  }
  if (flag) {
    int cnt = 0;
    for (int i = k - 2; i >= 0; i--) {
      if (v[i] == num) {
        cnt++;
        continue;
      }
      break;
    }
    cout << k - cnt - 1 << endl;
  } else
    cout << -1 << endl;
  return 0;
}
