#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  const size_t N = 50;
  long long n, k;
  cin >> n >> k;
  long long a[N];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long sum[N][N] = {};
  for (int l = 0; l < n; l++)
    for (int r = l; r < n; r++) {
      sum[l][r] = a[r];
      if (r > l) sum[l][r] += sum[l][r - 1];
    }
  long long ans = 0;
  for (long long test_bit = 1ll << 57; test_bit; test_bit >>= 1) {
    ans |= test_bit;
    bool possible[N][N] = {};
    for (int r = 0; r < n; r++) possible[r][0] = (sum[0][r] & ans) == ans;
    for (int splits = 1; splits < k; splits++) {
      for (int l = 1; l < n; l++)
        if (possible[l - 1][splits - 1])
          for (int r = l; r < n; r++)
            possible[r][splits] |= (sum[l][r] & ans) == ans;
    }
    if (!possible[n - 1][k - 1]) ans &= (~test_bit);
  }
  cout << ans;
}
