#include <bits/stdc++.h>
const long long N = 1e6 + 10;
const long long mod = 1e9 + 7;
long long dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
using namespace std;
long long a[55], p[55];
set<long long> dp[55][55];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i], p[i] = p[i - 1] + a[i];
  dp[1][1].insert(a[1]);
  for (long long i = 2; i <= n; i++) {
    dp[i][1].insert(p[i]);
    for (long long j = 2; j <= k && j <= i; j++) {
      for (long long l = j - 1; l < i; l++) {
        for (auto &e : dp[l][j - 1]) {
          dp[i][j].insert(e & (p[i] - p[l]));
          if (e > 2 * (p[i] - p[l])) break;
        }
      }
    }
  }
  cout << *dp[n][k].rbegin() << endl;
  return 0;
}
