#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
void debug(T first) {
  cout << first << "\n";
}
template <typename T, typename... Args>
void debug(T first, Args... args) {
  cout << first << " ";
  debug(args...);
}
long long read_ll() {
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  long long ret = 0;
  int neg = 0;
  if (c == '-') neg = 1, c = getchar();
  while (c >= '0' && c <= '9') {
    ret = 10 * ret + c - 48;
    c = getchar();
  }
  return neg ? -ret : ret;
}
vector<vector<bool> > sums;
int n, k;
vector<bool> bits(long long val) {
  vector<bool> ret;
  for (long long i = 0; i < 41; i++) {
    if ((val & (1LL << i)) > 0) {
      ret.push_back(1);
    } else
      ret.push_back(0);
  }
  return ret;
}
long long conv(vector<bool>& val) {
  long long c = 0;
  for (int i = 0; i <= 40; i++) {
    if (val[i]) c += (1LL << i);
  }
  return c;
}
void deb(int pos) {
  cout << pos << " [";
  for (auto val : sums) {
    cout << conv(val) << ",";
  }
  cout << "]";
  cout << '\n';
}
void deb1(int pos) {
  cout << pos << " [";
  for (auto val : sums) {
    for (auto v : val) cout << v;
    cout << ",";
  }
  cout << "]";
  cout << '\n';
}
int main() {
  cin >> n >> k;
  vector<long long> a(n + 1), prefixsum(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  prefixsum[0] = 0;
  for (int i = 1; i <= n; i++) prefixsum[i] = prefixsum[i - 1] + a[i];
  long long ans = 0;
  vector<long long> ss;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 1; j <= n - i; j++) {
      ss.push_back(prefixsum[j + i] - prefixsum[j - 1]);
    }
  }
  n = ss.size();
  long long dp[n + 1][k + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) dp[i][j] = 0;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][1] = max(dp[i - 1][1], ss[i - 1]);
    for (int j = 2; j <= min(i, k); j++) {
      dp[i][j] = max(dp[i - 1][j - 1] & ss[i - 1], dp[i - 1][j]);
    }
  }
  ans = 0;
  for (int i = k; i <= n; i++) {
    ans = max(ans, dp[i][k]);
  }
  cout << ans;
  return 0;
}
