#include <bits/stdc++.h>
using namespace std;
int x;
bool Iseq(int i) { return ((i != x)); }
int main() {
  vector<int> vec;
  long long int n, val, m, count1 = 0, count2 = -1, flage = 0, value, k;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> val;
    vec.push_back(val);
  }
  value = vec[m - 1];
  k = m - 1;
  val = count(vec.begin(), vec.end(), vec[m - 1]);
  for (int i = 0; i < n; i++) {
    if (val == n) {
      flage = 1;
      break;
    } else {
      vec.push_back(vec[m - 1]);
      if (vec[i] != value && vec[k] == value) {
        val++;
      }
      k++;
      count1++;
    }
  }
  if (flage == 0) {
    cout << "-1" << endl;
  } else {
    cout << count1;
  }
  return 0;
}
