#include <bits/stdc++.h>
using namespace std;
int main() {
  bool f = 0;
  int n, k, ans = 0;
  int i = 0;
  vector<int> a;
  map<int, int> mp;
  cin >> n >> k;
  a.resize(n);
  for (auto &i : a) {
    cin >> i;
    mp[i]++;
  }
  k--;
  for (int i = 0; i < n && mp.size() != 1; i++, k++) {
    f = 1;
    int t = 0;
    mp[a[k]]++;
    a.push_back(a[k]);
    mp[a[i]]--;
    if (!mp[a[i]]) {
      mp.erase(a[i]);
    }
    ans++;
    if (mp.size() == 1) {
      f = 0;
      break;
    }
  }
  cout << (!f ? ans : -1);
  return 0;
}
