#include <bits/stdc++.h>
using namespace std;
int n, k;
long long aux, nums[52], acum[52], dp[52][52][52];
long long solve(int ind, int lst, int lft) {
  if (dp[ind][lst][lft] != -1) return dp[ind][lst][lft];
  if (ind == n) return (lft == 0 && lst == n);
  long long ret = 0;
  ret += solve(ind + 1, lst, lft);
  if (lft && ((acum[ind] - (lst == 0 ? 0 : acum[lst - 1])) & aux) == aux)
    ret += solve(ind + 1, ind + 1, lft - 1);
  return dp[ind][lst][lft] = ret;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &nums[i]);
    acum[i] = nums[i];
    if (i) acum[i] += acum[i - 1];
  }
  long long atual = 0;
  aux = 0;
  for (int i = 60; i >= 0; i--) {
    aux = atual + (1ll << i);
    memset(dp, -1, sizeof dp);
    long long ret = solve(0, 0, k);
    if (ret) atual += (1ll << i);
  }
  printf("%lld\n", atual);
  return 0;
}
