#include <bits/stdc++.h>
using namespace std;
map<long long, int> vis;
int n, k;
long long sum = 0, a[1005];
long long cnt = 0, v[1000005];
long long cot[32];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]), sum += a[i], v[cnt++] = a[i], vis[a[i]]++;
  for (int i = 2; i <= n; i++) a[i] += a[i - 1];
  a[0] = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      v[cnt++] = a[j] - a[i - 1];
      vis[v[cnt - 1]]++;
      if (vis[v[cnt - 1]] >= k) ans = max(ans, v[cnt - 1]);
    }
  sort(v, v + cnt);
  long long anss = sum;
  for (int i = cnt - 1; i >= cnt - k; i--) anss &= v[i];
  ans = max(ans, anss);
  printf("%lld\n", ans);
}
