#include using namespace std; const int N = 2e5+3; int n, k; int a[N]; int niz[30]; int sajz[30]; unordered_set s[31]; int counter[200005]; unordered_set presjek(unordered_set a, unordered_set b) { unordered_set ret; for (const auto &e: a) { if (b.count(e)) ret.insert(e); } return ret; } int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", a+i); if(counter[a[i]] == k){ n--; i--; continue; } ++counter[a[i]]; } for (int i = 0; i <= 30; ++i) { for (int j = 0; j < n; ++j) { if (a[j] & (1<= 0; --i) { //if (sajz[poc] >= k) { // break; //} if ((int)s[i].size() >= k) { poc = i; break; } } //int tmp = niz[poc]; unordered_set q(s[poc].begin(), s[poc].end()); for (int i = poc-1; i >= 0; --i) { //if (__builtin_popcount(tmp & niz[i]) >= k) { //tmp &= niz[i]; //} auto t = presjek(q, s[i]); if ((int)t.size() >= k) { q = t; } } if ((int)q.size() >= k) { //printf("%d\n", (int)q.size()); int ans = a[*q.begin()]; for (const auto &e: q) { //printf("%d ", e); ans &= a[e]; } printf("%d", ans); } else { printf("0"); } return 0; }