#include <bits/stdc++.h>
using namespace std;
const int MX = 55;
long long a[MX], sum[MX];
bool vis[MX][MX];
bool can(long long ans, int n, int k) {
  vis[0][0] = 1;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= n; j++)
      if (vis[j][i]) {
        for (int k = j + 1; k <= n; k++) {
          if (((sum[k] - sum[j]) & ans) == ans) vis[k][i + 1] = 1;
        }
      }
  }
  return vis[n][k];
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i), sum[i] = sum[i - 1] + a[i];
  long long st = 0, en = 1LL << 60, mid;
  for (int it = 0; it < 100; it++) {
    mid = st + en >> 1;
    for (int i = 0; i < MX; i++)
      for (int j = 0; j < MX; j++) vis[i][j] = 0;
    if (can(mid, n, k))
      st = mid;
    else
      en = mid;
  }
  printf("%lld\n", st);
  return 0;
}
