#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = m; i <= n; i++) {
    if (a[i] != a[m]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  int sum = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i + 1]) sum = i;
  }
  cout << sum << '\n';
  return 0;
}
