#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  int c = 0;
  cin >> n >> k;
  vector<int> S;
  for (int i = 0; i < n; i++) {
    cin >> c;
    S.push_back(c);
  }
  for (int i = k; i < S.size(); i++) {
    if (S[i - 1] != S[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int j = k - 1; j >= 0; j--) {
    if (S[j] != S[j - 1]) {
      cout << j;
      return 0;
    }
  }
}
