#include <bits/stdc++.h>
using namespace std;
long long n, a[1001], ans, k, po[43];
vector<long long> x, y;
bool ck;
signed main() {
  cin >> n >> k;
  po[0] = 1;
  for (long long i = 1; i <= 42; i++) po[i] = po[i - 1] * 2;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) {
    long long ans = 0;
    for (long long j = i; j <= n; j++) {
      ans += a[j];
      x.push_back(ans);
    }
  }
  for (long long i = 42; i >= 0; i--) {
    y.clear();
    for (long long j = 0; j < x.size(); j++) {
      if ((x[j] & po[i])) y.push_back(x[j]);
    }
    if (y.size() < k) continue;
    ans += po[i];
    x.clear();
    x = y;
  }
  cout << ans;
}
