#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 123;
const long long INF = (long long)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
int a;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0), cin.tie(0);
  int n, k, l, ans = 0;
  cin >> n >> k >> l;
  for (int i = 1; i < n; i++) {
    cin >> a;
    if (a != l) {
      l = a;
      ans = i;
    }
  }
  if (ans + 1 > k)
    cout << -1;
  else
    cout << ans;
}
