#include <bits/stdc++.h>
#pragma G++ optimize(2)
using namespace std;
const int M = 55;
int n, k;
long long sum[M], ans, nw;
bool f[M][M];
bool check(long long x) {
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++)
      for (int p = 0; p < i; p++)
        f[i][j] |= f[p][j - 1] & ((sum[i] - sum[p] & x) == x);
  return f[n][k];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &sum[i]);
    sum[i] += sum[i - 1];
  }
  for (int i = 60; i >= 0; i--) {
    nw = ans | (1ll << i);
    if (check(nw)) ans |= (1ll << i);
  }
  printf("%lld", ans);
  return 0;
}
