#include <bits/stdc++.h>
using namespace std;
const long long int N = 55;
long long int n, k, mask;
long long int arr[N];
long long int cache[N][N];
long long int dp(long long int idx, long long int group) {
  if (idx == n + 1) {
    if (group == k) return 1LL;
    return 0LL;
  }
  long long int &ans = cache[idx][group];
  if (ans != -1) return ans;
  ans = 0;
  long long int sum = 0;
  for (long long int j = idx; j <= n; j++) {
    sum += arr[j];
    if ((mask & sum) == mask) {
      ans |= dp(j + 1, group + 1);
    }
  }
  return ans;
}
long long int check(long long int cur) {
  memset(cache, -1, sizeof(cache));
  mask = cur;
  return dp(1, 0);
}
void solve() {
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  long long int ans = 0;
  for (long long int i = 60; i >= 0; i--) {
    if (check(ans + (1LL << i))) {
      ans += (1LL << i);
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
