#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int N = 55;
int n, k;
vector<long long> arr(N);
vector<long long> pre(N);
bool possible(long long num) {
  bool dp[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = false;
    }
  }
  dp[0][0] = true;
  for (int seg = 1; seg <= k; seg++) {
    for (int r = 1; r <= n; r++) {
      for (int l = 0; l < r; l++) {
        if (dp[l][seg - 1] && (((pre[r] - pre[l]) & num) == num)) {
          dp[r][seg] = true;
          break;
        }
      }
    }
  }
  return dp[n][k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  pre[0] = 0;
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + arr[i];
  }
  long long res = 0;
  for (int i = N; i >= 0; i--) {
    if (possible(res | (1LL << i))) {
      res |= (1LL << i);
    }
  }
  cout << res;
  return 0;
}
