#include using namespace std; #define fio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); typedef long long ll; int main() { fio int n, k, t; cin >> n >> k; vector m(n); set curr; for(int i = 0; i < n; i++) { cin >> m[i]; curr.insert(i); } sort(m.begin(), m.end(), greater()); ll avail = 0; for(int i = 30; i >= 0; i--) { vector to_erase; int amt = 0; for(auto &a: curr) { if(m[a] & (1 << i)) amt++; } if(amt < k) continue; avail += (1 << i); for(auto &a: curr) { if(!(m[a] & (1 << i))) { to_erase.push_back(a); } } for(int j = 0; j < to_erase.size(); j++) curr.erase(to_erase[j]); } cout << avail << '\n'; return 0; }