#include <bits/stdc++.h>
using namespace std;
int ntest = 0, test = 0;
inline void init();
inline void run();
inline void stop() { ntest = test - 1; }
int main() {
  init();
  while (++test <= ntest) {
    run();
  }
  return 0;
}
const int INF = (int)1E9 + 5;
const double EPS = 1E-11;
const long long MOD = (long long)1E9 + 7;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
inline void init() { ntest = 1; }
vector<int> a;
inline void run() {
  int n, k;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
  }
  for (int i = (n - 2); i >= (0); i--) {
    if (a[i] != a[i + 1]) {
      if (i < k - 1) {
        cout << (1 + i);
        return;
      } else {
        cout << -1;
        return;
      }
    }
  }
  cout << 0;
}
