#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  unsigned long long a, b;
  cin >> a >> b;
  unsigned long long c[a + 1];
  for (unsigned long long i = 1; i <= a; i++) cin >> c[i];
  unsigned long long x = 1;
  for (unsigned long long i = b; i <= a; i++) {
    if (c[i] != c[b]) {
      x = 0;
      break;
    }
  }
  unsigned long long count = 0;
  if (x == 1) {
    for (unsigned long long i = b; i >= 0; i--) {
      count++;
      if (c[i] != c[b]) {
        break;
      }
    }
    cout << b - count + 1 << endl;
  } else
    cout << -1 << endl;
}
