#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, fg = 1, d;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  d = v[k - 1];
  for (int i = k; i < n; i++) {
    if (v[i] != d) {
      fg = 0;
      break;
    }
  }
  if (!fg)
    cout << "-1" << endl;
  else {
    int cnt = 0;
    for (int i = k - 2; i >= 0; i--) {
      if (v[i] == d)
        cnt += 1;
      else
        break;
    }
    cout << k - cnt - 1 << endl;
  }
  return 0;
}
