#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;

constexpr int N = 2e+5 + 5, oo = 2e+18;

void _() {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int lo = 0, hi = 1e9, ans = -1;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    int val = 0, part = 0;
    for (int i = 0; i < n; ++i) {
      val |= a[i];
      if ((val & mid) == mid) {
        ++part;
        val = 0;
      }
    }
    if (part >= k) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << '\n';
}

signed main() {
  pasha
  int t = 1;
  // cin >> t;
  for (int cs = 1; cs <= t; ++cs) {
    _();
    // cout << '\n';
  }
}