#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, k, dp[N][N];
long long a[N], sum[N], dq;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (int i = 60; i >= 0; i--) {
    dq |= (long long)1 << i;
    dp[0][0] = 1;
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= k; l++) {
        dp[j][l] = 0;
        for (int o = j - 1; o >= 0; o--)
          if (((sum[j] - sum[o]) & dq) == dq) dp[j][l] |= dp[o][l - 1];
      }
    if (!dp[n][k]) dq ^= (long long)1 << i;
  }
  printf("%lld", dq);
}
