#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
vector<int> v;
void test_case() {
  cin >> n >> k;
  v.resize(n, 0);
  for (auto& x : v) cin >> x;
  sort(v.begin(), v.end());
  int ans = -1;
  if (k == 0)
    ans = v.front() - 1;
  else
    ans = v[k - 1];
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (v[i] <= ans) ++cnt;
  if (cnt != k || !(ans >= 1 && ans <= 1e9)) ans = -1;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  test_case();
  return 0;
}
