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