#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector <int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto can = [&](int x) {
    int cur = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cur |= a[i];
      if ((cur & x) == x) {
        cur = 0;
        cnt++;
      }
    }
    return cnt >= k;
  };
  int x = 0;
  for (int i = 30; i >= 0; i--) {
    if (can(x | (1 << i))) {
      x |= 1 << i;
    }
  }
  cout << x << '\n';
  return 0;
}