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