function Main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0].split(' ')[0], 10),
    K = parseInt(args[0].split(' ')[1], 10);
  const a = args[1].split(' ').map(n => parseInt(n, 10));
  var sub = [];

  a.forEach((val, i) => {
    var tmp = 0;
    for (var j = i; j < a.length; j++) {
      tmp += a[j];
      sub.push(tmp);
    }
  });

  sub.sort(function(a, b) {
    return a - b;
  });

  var max = sub[sub.length - 1];
  for (var k = 1; k < K; k++) {
    max = max & sub[sub.length - k - 1];
  }
  console.log(max);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
