#include <bits/stdc++.h>
using namespace std;
const long long N = 60;
bool f[N][N];
long long n, k, ans;
long long a[N], sum[N];
bool check(long long x) {
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (long long i = 1; i <= k; i++)
    for (long long j = 1; j <= n; j++)
      for (long long u = 0; u < j; u++)
        f[i][j] |= f[i - 1][u] && ((x & (sum[j] - sum[u])) == x);
  return f[k][n];
}
signed main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &a[i]), sum[i] = sum[i - 1] + a[i];
  for (long long i = N; i >= 0; i--)
    if (check(ans | (1ll << i))) ans |= (1ll << i);
  printf("%lld\n", ans);
  return 0;
}
