#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const long long inf32 = 1e9 + 9;
const long long inf64 = 1e18 + 18;
const long long mod = 1e9 + 7;
const int N = 53;
bool dp[N][N];
long long ar[N], pref[N];
int n, k;
bool check(long long cur) {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) dp[i][j] = false;
  }
  for (int i = 1; i <= n; ++i) dp[1][i] = (pref[i] & cur) == cur;
  for (int j = 2; j <= k; ++j) {
    for (int e = j; e <= n; ++e) {
      for (int s = j; s <= e; ++s) {
        dp[j][e] |=
            dp[j - 1][s - 1] && (((pref[e] - pref[s - 1]) & cur) == cur);
      }
    }
  }
  return dp[k][n];
}
void solve() {
  cin >> n >> k;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> ar[i];
    pref[i] = pref[i - 1] + ar[i];
  }
  long long cur = 0;
  for (int i = 60; i >= 0; --i) {
    if (check(cur | (1LL << i))) cur |= (1LL << i);
  }
  cout << cur;
}
int main() {
  solve();
  return 0;
}
