#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { constexpr int B = 30; int n; ll k; cin >> n >> k; vector a(n); for (int& a_i : a) cin >> a_i; ranges::sort(a); const auto calc_mid = [&](const int l, const int r, const int bit) -> int { int mid = l; while ((a[mid] >> bit & 1) == 0 && mid <= r) ++mid; return mid; }; vector> segs{{0, n - 1}}; vector> nsegs; int bit = B - 1, ans = 0; for (; bit >= 0; --bit) { vector> tmp; ll num = 0; for (const auto& [l, r] : segs) { const int mid = calc_mid(l, r, bit); num += (mid - l) * (mid - l - 1LL) / 2; num += (r - mid + 1LL) * (r - mid) / 2; if (l < mid - 1) tmp.emplace_back(l, mid - 1); if (mid < r) tmp.emplace_back(mid, r); if (l <= mid - 1 && mid <= r) nsegs.emplace_back(l, mid - 1, mid, r); } if (num < k) { k -= num; ans = 1 << bit; --bit; break; } segs.swap(tmp); nsegs.clear(); } vector> tmp1, tmp2; for (; bit >= 0; --bit) { tmp1.clear(); tmp2.clear(); ll num = 0; for (const auto& [xl, xr, yl, yr] : nsegs) { const int lmid = calc_mid(xl, xr, bit); const int rmid = calc_mid(yl, yr, bit); num += ll{lmid - xl} * (rmid - yl); num += (xr - lmid + 1LL) * (yr - rmid + 1LL); if (xl <= lmid - 1 && yl <= rmid - 1) tmp1.emplace_back(xl, lmid - 1, yl, rmid - 1); if (lmid <= xr && rmid <= yr) tmp1.emplace_back(lmid, xr, rmid, yr); if (xl <= lmid - 1 && rmid <= yr) tmp2.emplace_back(xl, lmid - 1, rmid, yr); if (lmid <= xr && yl <= rmid - 1) tmp2.emplace_back(lmid, xr, yl, rmid - 1); } if (num < k) { k -= num; ans |= 1 << bit; nsegs.swap(tmp2); } else { nsegs.swap(tmp1); } } cout << ans << '\n'; return 0; }