#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
int n, k;
long long pre[maxn], ans;
int dp[maxn][maxn];
int check(long long x) {
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++) {
    if ((pre[i] & x) == x) dp[i][1] = 1;
    for (int j = 1; j < i; j++) {
      if (((pre[i] - pre[j]) & x) != x) continue;
      for (int h = 2; h <= min(k, i); h++) dp[i][h] |= dp[j][h - 1];
    }
  }
  return dp[n][k];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &pre[i]);
    pre[i] += pre[i - 1];
  }
  for (int i = 60; i >= 0; i--) {
    if (check(ans | (1LL << i))) ans |= 1LL << i;
  }
  printf("%lld\n", ans);
  return 0;
}
