#include <bits/stdc++.h>
using namespace std;
long long N, K, curpow, a[10001];
vector<long long> s[2];
long long llog(long long n) {
  long long ans = 1LL;
  while (n != 1LL) {
    n /= 2LL;
    ans++;
  }
  return ans;
}
long long get_ans(int m) {
  if (curpow == -1LL) {
    long long ans = s[m][0];
    for (long long x : s[m]) ans &= x;
    return ans;
  }
  s[1 - m].clear();
  for (long long x : s[m]) {
    if (x & (1 << curpow)) s[1 - m].push_back(x);
  }
  if (s[1 - m].size() == K) {
    curpow = -1;
    return get_ans(1 - m);
  } else if (s[1 - m].size() > K) {
    curpow--;
    return get_ans(1 - m);
  } else {
    curpow--;
    return get_ans(m);
  }
}
int main() {
  scanf("%lld %lld", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", a + i);
    a[i] += a[i - 1];
  }
  for (int i = 0; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      long long tmp = a[j] - a[i];
      s[0].push_back(tmp);
      curpow = max(curpow, llog(tmp));
    }
  }
  printf("%lld\n", get_ans(0));
  return 0;
}
