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