#include <bits/stdc++.h>
using namespace std;
int n, k, f[55][55];
long long ans, da[55], sum[55];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &da[i]);
    sum[i] = sum[i - 1] + da[i];
  }
  for (int p = 60; p >= 0; --p) {
    memset(f, 0, sizeof(f));
    ans += (1ll << p);
    f[0][0] = 1;
    for (int j = 1; j <= k; ++j)
      for (int i = 1; i <= n; ++i)
        for (int x = 0; x < i; ++x)
          if (f[x][j - 1] && (((sum[i] - sum[x]) & ans) >= ans)) f[i][j] = 1;
    if (!f[n][k]) ans -= (1ll << p);
  }
  printf("%I64d\n", ans);
  return 0;
}
