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