#include <bits/stdc++.h>
using namespace std;
long long dp[55][55], sum[55], ans;
int n, k;
int judge(long long x) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      if (dp[i][j]) {
        for (int l = i + 1; l <= n; l++) {
          if (((sum[l] - sum[i]) & x) == x) {
            dp[l][j + 1] = 1;
          }
        }
      }
    }
  }
  return dp[n][k];
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> k) {
    ans = 0;
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> sum[i];
      sum[i] += sum[i - 1];
    }
    for (int i = 60; i >= 0; i--) {
      if (judge(ans | ((long long)1 << i))) {
        ans |= (long long)1 << i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
