#include <bits/stdc++.h>

using namespace std;

const int LG = 32;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> cnt(LG);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < LG; j++) {
      if (a[i] & (1 << j)) {
        cnt[j].push_back(i);
      }
    }
  }
  vector<int> ans;
  for (int p = LG - 1; p >= 0; p--) {
    ans.push_back(p);
    int comp = 0;
    vector<bool> check(ans.size(), 0);
    int cntCheck = ans.size();
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < ans.size(); j++) {
        if (check[j]) continue;
        if (a[i] & (1 << ans[j])) {
          check[j] = 1;
          cntCheck--;
        }
      }
      if (cntCheck == 0) {
        cntCheck = ans.size();
        fill(check.begin(), check.end(), 0);
        comp++;
      }
    }
    if (comp < k) {
      ans.pop_back();
    }
  }
  int answ = 0;
  for (int i = 0; i < ans.size(); i++) {
    answ += 1 << ans[i];
  }
  cout << answ;
}