#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[55], z[55];
bool dp[55][55];
bool sub(long long a, long long b) { return (b & a) == b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    z[i] = z[i - 1] + a[i];
  }
  long long mask = 0;
  for (long long v = 61; v >= 0; v--) {
    mask += 1ll << v;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = true;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= k; j++) {
        for (long long y = 0; y < i; y++) {
          dp[i][j] |= dp[y][j - 1] && sub(z[i] - z[y], mask);
        }
      }
    }
    if (!dp[n][k]) mask -= 1ll << v;
  }
  cout << mask;
}
