#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100], d[51][51], val, sum[100], dap;
int pro(long long x) {
  int i, j, l;
  memset(d, 0, sizeof d);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= k; j++) {
      if (j == 1 && (sum[i] & x) == x) d[i][j] = 1;
      for (l = 1; l < i; l++) {
        if (d[l][j - 1] == 1 && ((sum[i] - sum[l]) & x) == x) d[i][j] = 1;
      }
    }
  }
  if (d[n][k] == 1) return 1;
  return 0;
}
int main() {
  long long i;
  scanf("%lld %lld", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (i = 60; i >= 0; i--) {
    val = (long long)1 << i;
    if (i == 5) {
      val = 1 << i;
    }
    if (pro(val + dap) == 1) dap += val;
  }
  printf("%lld", dap);
  return 0;
}
