#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 50 + 10;
long long a[N];
int dp[N][N];
int main() {
  long long mask = 0;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int o = 60; o >= 0; o--) {
    mask |= 1LL << o;
    memset((dp), (0), sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= n; j++) {
        long long sum = 0;
        for (int t = j; t >= 1; t--) {
          sum += a[t];
          if (((sum & mask) == mask) && dp[i - 1][t - 1] == 1) {
            dp[i][j] = 1;
            break;
          }
        }
      }
    }
    if (dp[k][n] == 0) mask ^= 1LL << o;
  }
  cout << mask << endl;
  return 0;
}
