#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll N = 65, mod = 1e9 + 7;
const ll inf = 1e18;
struct cmp {
  bool operator()(pair<int, int> a, pair<int, int> b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first > b.first;
  }
};
ll power(ll x, ll p) {
  ll r = 1ll;
  x = x % mod;
  while (p > 0) {
    if (p & 1) r = (r * x) % mod;
    p = p >> 1;
    x = (x * x) % mod;
  }
  return r;
}
vector<ll> sum;
ll num;
int dp[N][N];
int rec(ll n, ll k) {
  if (n == 0 && k == 0) {
    return 1;
  }
  if (n < k || n == 0 || k == 0) {
    return 0;
  }
  if (dp[n][k] != -1) return dp[n][k];
  bool flag = 0;
  for (int i = n; i > 0; i--) {
    ll s = sum[n] - sum[i - 1];
    if ((s & num) == num) {
      if (rec(i - 1, k - 1)) {
        flag = 1;
        break;
      }
    }
  }
  dp[n][k] = flag;
  if (flag)
    return 1;
  else
    return 0;
}
void solve() {
  ll n, k;
  cin >> n >> k;
  sum.clear();
  sum.push_back(0);
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    a += sum.back();
    sum.push_back(a);
  }
  ll ans = 0;
  for (int i = 61; i >= 0; i--) {
    num = ans + (1ll << i);
    memset(dp, -1, sizeof(dp));
    if (rec(n, k)) {
      ans = num;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1, p;
  for (p = 1; p <= t; p++) {
    solve();
  }
  return 0;
}
