#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int dp[10 * N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  int lb = 0, rb = a[n - 1] + 1;
  while (rb - lb > 1) {
    int mb = (lb + rb) / 2;
    for (int i = 0; i < 10 * N; ++i)
      if (i <= mb)
        dp[i] = (i < mb ? 0 : 1);
      else
        dp[i] = max(dp[i - 1], dp[i / 2] + dp[(i + 1) / 2]);
    int cur = 0;
    for (int i = 0; i < n && cur < k; ++i) cur += dp[a[i]];
    if (cur >= k)
      lb = mb;
    else
      rb = mb;
  }
  printf("%d", lb ? lb : -1);
  return 0;
}
