#include <bits/stdc++.h>
using namespace std;

const int LG = 32;

int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[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;
}