#include <bits/stdc++.h>
const long long N = 55;
const long long mod = 1e9 + 7;
using namespace std;
long long a[N], k, n;
bool is_possible(long long x) {
  bool possible[N][N];
  memset(possible, false, sizeof(possible));
  possible[0][0] = 1;
  for (long long part = 1; part <= k; ++part) {
    for (long long right = 1; right <= n; right++) {
      for (long long left = 0; left < right; left++) {
        if (possible[left][part - 1] and ((a[right] - a[left]) & x) == x) {
          possible[right][part] = 1;
          break;
        }
      }
    }
  }
  return possible[n][k];
}
void solve() {
  long long x = 0, y = 0, c = 0, q, ans = 0;
  cin >> n >> k;
  a[0] = 0;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
  }
  for (long long bits = 61; bits >= 0; --bits) {
    if (is_possible(ans | (1LL << bits))) ans |= (1LL << bits);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
