#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long b[1000005];
int k;
long long work(long long *c, int m, int b) {
  if (b < 0) return 0;
  int cnt = 0;
  for (int i = m; i--;) cnt += c[i] >> b & 1;
  if (cnt >= k) {
    int j = m;
    for (int i = m; i--;)
      if (c[i] >> b & 1) c[--j] = c[i];
    return (1ll << b) | work(c + j, m - j, b - 1);
  } else
    return work(c, m, b - 1);
}
int main() {
  int n;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  int m = 0;
  for (int i = 1; i <= n; ++i) {
    long long s = 0;
    for (int j = i; j <= n; ++j) {
      s += a[j];
      b[m++] = s;
    }
  }
  printf("%lld\n", work(b, m, 40));
}
