#include <bits/stdc++.h>
using namespace std;
long long dp[1010][1010], a[1010], sum[1010], n, k, ans;
bool check(long long now) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= k; j++)
      for (long long l = 0; l < i; l++)
        dp[i][j] |= dp[l][j - 1] & (((sum[i] - sum[l]) & now) == now);
  return dp[n][k];
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &sum[i]), sum[i] += sum[i - 1];
  for (long long i = 60; ~i; i--) {
    long long now = ans | 1LL << i;
    if (check(now)) ans = now;
  }
  printf("%lld", ans);
}
