#include <bits/stdc++.h>
using namespace std;
int n, k;
long long sum = 0, a[1005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), sum += a[i];
  long long p = 1, q = 1;
  long long ans = sum;
  k--;
  while (k--) {
    ans &= (sum - a[q++]);
    if (q > n) q = p + 1, sum -= a[p], p++;
  }
  printf("%lld\n", ans);
}
