#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int x, y, arr[100000];
  bool bad = false;
  cin >> x >> y;
  for (int i = 0; i < x; i++) cin >> arr[i];
  for (int v = y; v < x; v++) {
    if (arr[v] != arr[v - 1]) bad = true;
  }
  int index = -1;
  if (bad)
    cout << "-1" << endl;
  else {
    for (int v = y - 1; v >= 0; v--) {
      if (arr[v] != arr[y - 1]) {
        index = v;
        break;
      }
    }
    if (index == -1)
      cout << 0 << endl;
    else
      cout << index + 1 << endl;
  }
}
