#include <bits/stdc++.h>
using namespace std;
const long long N = 55;
const long long K = 61;
long long n;
long long a[N];
long long p[N];
long long Dp[N][N];
bool Rec(long long i, long long k, long long Mask) {
  if (k < 0) return false;
  if (i == n + 1) return k == 0;
  if (Dp[i][k] + 1) return Dp[i][k];
  bool Res = false;
  for (long long j = i; j <= n; ++j) {
    long long Sum = p[j] - p[i - 1];
    if ((Sum | Mask) == Sum) Res |= Rec(j + 1, k - 1, Mask);
  }
  return Dp[i][k] = Res;
}
int main() {
  long long k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++)
    scanf("%I64d", a + i), p[i] = a[i] + p[i - 1];
  long long Mask = 0;
  for (long long bit = K - 1; ~bit; --bit) {
    memset(Dp, -1, sizeof(Dp));
    if (Rec(1, k, Mask | (1LL << bit))) Mask |= (1LL << bit);
  }
  cout << Mask << endl;
}
