#include <bits/stdc++.h>
using namespace std;
const long long maxn = 50 + 11;
const long long inf = 1e18 + 10;
long long n, k, a[maxn];
bool dp[maxn][maxn];
bool check(long long x) {
  for (long long i = 0; i < maxn; i++)
    for (long long j = 0; j < maxn; j++) dp[i][j] = 0;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += a[i];
    if ((sum & x) == x) {
      dp[i][1] = 1;
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 2; j <= min((i + 1), k); j++) {
      sum = 0;
      for (long long f = i; f >= j - 1; f--) {
        sum += a[f];
        if ((sum & x) == x) dp[i][j] |= dp[f - 1][j - 1];
      }
    }
  }
  return dp[n - 1][k];
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = maxn - 1; i >= 0; i--) {
    if (check((1LL << i) + ans)) {
      ans += (1LL << i);
    }
  }
  cout << ans << "\n";
  return 0;
}
