#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k, A[100005];
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = k; i <= n; i++) {
    if (A[i] != A[k]) {
      cout << "-1\n";
      return 0;
    }
  }
  int i = k;
  for (; i >= 1; i--)
    if (A[i] != A[k]) break;
  cout << i << '\n';
  return 0;
}
