#include <bits/stdc++.h>
using namespace std;
long long int a[52], mask, k, n;
long long int cache[52][52];
long long int dp(long long int pos, long long int groups) {
  if (pos == n + 1) {
    if (groups == k + 1)
      return true;
    else
      return false;
  }
  long long int &ans = cache[pos][groups];
  if (ans != -1) return ans;
  ans = 0;
  long long int cur = 0;
  for (long long int i = pos; i <= n; i++) {
    cur += a[i];
    if ((cur & mask) == mask) {
      ans |= dp(i + 1, groups + 1);
    }
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  long long int ans = 0;
  for (long long int i = 57; i >= 0; i--) {
    memset(cache, -1, sizeof cache);
    mask = ans + (1LL << i);
    if (dp(1, 1)) ans += (1LL << i);
  }
  cout << ans;
  return 0;
}
