#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int k, n;
long long a[maxn];
bool dp[maxn][maxn];
bool can(long long x) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      for (int kk = 0; kk < i; kk++) {
        dp[i][j] |= dp[kk][j - 1] & (((a[i] - a[kk]) & x) == x);
      }
    }
  }
  return dp[n][k];
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  long long ans = 0;
  for (int i = 60; i >= 0; i--) {
    long long f = (1LL << i);
    long long tmp = ans | f;
    if (can(tmp)) ans |= f;
  }
  cout << ans << endl;
  return 0;
}
