#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[59], s[59];
bool dp[59][59];
int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
bool check(long long x) {
  int i, j, k;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      for (k = 0; k < i; k++)
        if (dp[k][j - 1] && ((s[i] - s[k] & x) == x)) {
          dp[i][j] = 1;
          break;
        }
  return dp[n][m];
}
int main() {
  n = read();
  m = read();
  int i;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    s[i] = s[i - 1] + a[i];
  }
  for (i = 60; i >= 0; i--)
    if (check(ans | 1ll << i)) ans |= 1ll << i;
  printf("%lld\n", ans);
  return 0;
}
