#include <bits/stdc++.h>
using namespace std;
int a[1010];
long long b[1010];
vector<long long> v;
int main() {
  int i, j, n, k;
  scanf("%d %d", &n, &k);
  b[0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = b[i - 1] + a[i];
  }
  long long sum;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      sum = b[j] - b[i - 1];
      v.push_back(sum);
    }
  }
  long long res = 0;
  for (i = 40; i >= 0; i--) {
    sum = res | (long long)pow(2, i);
    int cnt = 0;
    for (j = 0; j < n * (n + 1) / 2; j++) {
      if ((v[j] & sum) == sum) cnt++;
    }
    if (cnt >= k) res += (long long)pow(2, i);
  }
  printf("%lld\n", res);
  return 0;
}
