#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);
      }
    }
  }
  int ans = 0;
  for (int p = LG - 1; p >= 0; p--) {
    ans += 1 << p;
    int tmp = 0;
    int comp = 0;
    for (int i = 0; i < n; i++) {
      tmp |= a[i];
      if ((tmp & ans) == ans) {
        tmp = 0;
        comp++;
      }
    }
    if (comp < k) {
      ans -= 1 << p;
    }
  }
  cout << ans;
}