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