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