#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define sz(s) (int)(s.size())
#define gcd __gcd
using pii = pair<int, int>;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<vector<pii>> bit(33);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < 33; ++j) {
            if ((a[i] >> j) & 1) {
                bit[j].push_back({a[i], i});
            }
        }
    }
    int ans = 0;
    vector<int> pos(k, -1);
    for (int i = 32; i > -1; --i) {
        if (sz(bit[i]) < k) continue;
        ans |= (1ll << i);
    }
    cout << ans << endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt =1 ;
    // cin >> tt;
    while (tt --) {
        solve();
    }
    return 0;
}
