#include <bits/stdc++.h>
using namespace std;
inline void out(int a) { printf("%d\n", a); }
inline void out(int a, int b) { printf("%d %d\n", a, b); }
inline void outf(double a) { printf("%3.lf\n", a); }
inline void outf(double a, double b) { printf("%3.lf %3.lf\n", a, b); }
inline void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
long long data[1000005];
long long dp[10000005];
long long calc(long long a, long long bs) {
  if (a < bs) return 0;
  if (a == bs) return 1;
  if (dp[a] != -1) return dp[a];
  long long ret = 0;
  if (a % 2 == 0) {
    ret = 2 * calc(a / 2, bs);
    if (ret == 0) return dp[a] = 1;
  } else {
    ret = calc(a / 2, bs) + calc(a / 2 + 1, bs);
    if (ret == 0) return dp[a] = 1;
  }
  return dp[a] = ret;
}
long long n, k;
int find(int x) {
  int l = 0, r = n;
  while (l < r) {
    int m = (l + r) / 2;
    if (data[m] < x)
      l = m + 1;
    else
      r = m;
  }
  return l;
}
int main() {
  scanf("%I64d%I64d", &n, &k);
  long long l = 0, r = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    scanf("%I64d", &data[i]);
    r += data[i];
  }
  sort(data, data + n);
  r /= k;
  r++;
  if (r == 1) {
    cout << -1 << endl;
    return 0;
  }
  while (l < r) {
    long long mid = (l + r) / 2;
    int j = find(mid);
    long long tot = 0;
    memset(dp, -1, sizeof dp);
    for (int(i) = (j); (i) <= (n - 1); (i)++) {
      tot += calc(data[i], mid);
      if (tot >= k) break;
    }
    if (tot >= k)
      l = mid + 1;
    else
      r = mid;
  }
  if (l == 1)
    printf("-1\n");
  else
    printf("%I64d\n", l - 1);
  return 0;
}
