#include <bits/stdc++.h>
using namespace std;
long long int dp[55][55];
long long int arr[55], sum[55];
int main() {
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  sum[0] = 0;
  sum[1] = arr[1];
  for (long long int i = 2; i <= n; i++) sum[i] = sum[i - 1] + arr[i];
  long long int ans = 0;
  for (long long int i = 60; i >= 0; i--) {
    long long int dd = ans | ((long long int)1 << i);
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (long long int j = 1; j <= k; j++) {
      for (long long int ii = j; ii <= n; ii++) {
        for (long long int l = j - 1; l < ii; l++) {
          long long int ff = sum[ii] - sum[l];
          if (dp[j - 1][l] == 1 && ((ff & dd) == dd)) {
            dp[j][ii] = 1;
          }
        }
      }
    }
    if (dp[k][n] == 1) ans = dd;
  }
  cout << ans << endl;
}
