#include <bits/stdc++.h>
using namespace std;
const long long N = 55;
const long long MOD = 1e9 + 7;
long long n, k, ans, a[N], prfx[N], dp[N][N];
bool chk(long long mask) {
  memset(dp, 0, sizeof(dp));
  for (long long i = 1; i <= n; i++) dp[i][1] = ((prfx[i] & mask) == mask);
  for (long long j = 2; j <= k; j++) {
    for (long long i = 1; i <= n; i++) {
      for (long long k = 1; k < i; k++) {
        if (dp[k][j - 1] && ((prfx[i] - prfx[k]) & mask) == mask)
          dp[i][j] = true;
      }
    }
  }
  return dp[n][k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) prfx[i] = prfx[i - 1] + a[i];
  for (long long bit = 62; bit >= 0; bit--)
    if (chk(ans | (1ll << bit))) ans |= (1ll << bit);
  cout << ans;
}
