#include <bits/stdc++.h>
const int ms = 55;
long long a[ms];
long long sum[ms][ms];
bool can[ms][ms];
int main() {
  srand(time(0));
  int n, k;
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      sum[i][j + 1] = sum[i][j] + a[j];
    }
  }
  long long ans = 0;
  for (int e = ms; e >= 0; e--) {
    memset(can, 0, sizeof can);
    can[0][0] = true;
    long long want = ans + (1LL << e);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k; j++) {
        if (!can[i][j]) continue;
        for (int k = i + 1; k <= n; k++) {
          if ((sum[i][k] & want) == want) {
            can[k][j + 1] = true;
          }
        }
      }
    }
    if (can[n][k]) {
      ans = want;
    }
  }
  std::cout << ans << std::endl;
}
