#include <bits/stdc++.h>
using namespace std;
void Code_780A_AndryushaAndSocks();
void Code_625A_GuestFromThePast();
void Code_799A_CarrotCakes();
void Code_222A_ShooshunsAndSequence();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Code_222A_ShooshunsAndSequence();
  return 0;
}
inline void Code_222A_ShooshunsAndSequence() {
  int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int pivot = a[k], operations = 0;
  for (int i = k; i <= n; ++i) {
    if (a[i] != pivot) {
      cout << "-1";
      return;
    }
  }
  for (int i = k - 1; i >= 1; --i) {
    if (a[i] != pivot) {
      operations = i;
      break;
    }
  }
  cout << operations;
}
inline void Code_799A_CarrotCakes() {
  int n, t, k, d;
  cin >> n >> t >> k >> d;
  int withoutOven = (n % k == 0 ? t * (n / k) : t * (n / k + 1));
  if (d + t >= withoutOven)
    cout << "NO";
  else
    cout << "YES";
}
inline void Code_625A_GuestFromThePast() {
  long long int n, a, b, c, netCost;
  cin >> n >> a >> b >> c;
  netCost = b - c;
  if (netCost >= a || n < b)
    cout << n / a;
  else
    cout << (n - b) / netCost + 1 + (n - netCost * ((n - b) / netCost + 1)) / a;
}
inline void Code_780A_AndryushaAndSocks() {
  int n;
  cin >> n;
  int x[2 * n + 1];
  int count[n + 1];
  for (int i = 0; i <= n; ++i) count[i] = 0;
  for (int i = 1; i <= 2 * n; ++i) cin >> x[i];
  int onTable = 0, maxOnTable = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    if (!count[x[i]]) {
      ++count[x[i]];
      ++onTable;
      maxOnTable = max(maxOnTable, onTable);
    } else
      --onTable;
  }
  cout << maxOnTable;
}
