#include <bits/stdc++.h>
using namespace std;
int n, target, ar[100005];
set<int> x;
int main() {
  cin >> n >> target;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = target - 1; i < n; i++) x.insert(ar[i]);
  if (x.size() == 1) {
    int pos = target - 1;
    for (int i = target - 1; i > 0; i--) {
      if (ar[i] == ar[i - 1])
        pos = i - 1;
      else
        break;
    }
    cout << pos;
  } else
    cout << -1;
}
