#include <bits/stdc++.h>
using namespace std;
const int MAX = 55;
long long a[MAX], pre[MAX];
bool dp[MAX][MAX];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    pre[i] = pre[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 60; i >= 0; i--) {
    ans += (1LL << i);
    memset(dp, false, sizeof(dp));
    dp[0][0] = true;
    for (int j = 1; j <= m; j++)
      for (int k = 0; k <= n; k++) {
        if (!dp[j - 1][k]) continue;
        for (int l = k + 1; l <= n; l++)
          if (((pre[l] - pre[k]) & ans) == ans) dp[j][l] = true;
      }
    if (!dp[m][n]) ans -= (1LL << i);
  }
  printf("%I64d\n", ans);
  return 0;
}
