#include <bits/stdc++.h>
const int N = 55;
int n, k;
long long a[N];
bool f[N][N];
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 k = 0; k < i; ++k) {
        f[i][j] |= f[k][j - 1] & (((a[i] - a[k]) & x) == x);
      }
    }
  }
  return f[n][k];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), a[i] += a[i - 1];
  long long ans = 0;
  for (int i = 60; i >= 0; --i) {
    long long now = ans | (1LL << i);
    if (check(now)) ans |= (1LL << i);
  }
  printf("%lld\n", ans);
  return 0;
}
