#include <bits/stdc++.h>
using namespace std;
int n, k;
long long ara[55];
long long prefix;
bool vis[55][55];
bool dp[55][55];
long long setBit(long long mask, int pos) {
  return mask = (mask | (1LL << pos));
}
bool checkBit(long long mask, int pos) { return ((mask | (1LL << pos)) != 0); }
long long resetBit(long long mask, int pos) {
  return mask = (mask & ~(1LL << pos));
}
bool f(int shelf, int book) {
  if (shelf == (k - 1)) {
    long long sum = 0;
    for (int i = book; i < n; i++) sum += ara[i];
    if ((sum & prefix) == prefix) return true;
    return false;
  }
  if (vis[shelf][book]) return dp[shelf][book];
  vis[shelf][book] = true;
  long long sum = 0;
  bool res = false;
  for (int i = book; (n - i - 1) >= (k - shelf - 1); i++) {
    sum += ara[i];
    if ((sum & prefix) == prefix && f(shelf + 1, i + 1)) res = true;
  }
  return dp[shelf][book] = res;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", &ara[i]);
  prefix = 0;
  for (int bit = 60; bit >= 0; bit--) {
    prefix = setBit(prefix, bit);
    memset(vis, false, sizeof(vis));
    if (!f(0, 0)) prefix = resetBit(prefix, bit);
  }
  printf("%lld\n", prefix);
  return 0;
}
