#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline int getmin(Tp &x, Tp y) {
  return y < x ? x = y, 1 : 0;
}
template <typename Tp>
inline int getmax(Tp &x, Tp y) {
  return y > x ? x = y, 1 : 0;
}
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') f = 1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (f) x = -x;
}
int n, k, f[55][55];
long long tmp, ans, a[55], sum[55];
int main() {
  read(n);
  read(k);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int x = 60; ~x; x--) {
    tmp = ans | (1ll << x);
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= n; i++) f[i][1] = ((sum[i] & tmp) == tmp);
    for (int i = 2; i <= n; i++)
      for (int j = 2; j <= i && j <= k; j++) {
        for (int r = 1; r < i; r++)
          f[i][j] |= f[r][j - 1] & (((sum[i] - sum[r]) & tmp) == tmp);
      }
    if (f[n][k]) ans |= 1ll << x;
  }
  printf("%lld\n", ans);
  return 0;
}
