#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, streak = 0;
  bool possible = true;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int num = arr[k - 1];
  for (int i = k; i < n; i++) {
    if (arr[i] != num) {
      possible = false;
      break;
    }
  }
  if (possible) {
    for (int i = 0; i < n; i++) {
      if (arr[i] == num) {
        streak++;
      } else {
        streak = 0;
      }
    }
    cout << n - streak << '\n';
  } else {
    cout << -1 << '\n';
  }
}
