function main(input){
    var lines = input.replace('\n',' ');
    lines = lines.split(" ");
    var N = Number(lines[0]);
    var K = Number(lines[1]);
    lines.splice(0,2);

    var utu=[K];

    var max=0;
    var mem=0;
    var w=0;
    for (var i=0;i<N ;i++ ) {
   		for (var u=i;u<N ;u++ ) {
			mem+=Number(lines[u]);
		}
		utu[w]=mem;
		w++;
		mem=0;
    }
    utu=utu.sort(compareNumbers);
    max=utu[N];
    for (var i=1;i<K;i++){
    	var v=g-i;
    	max&=utu[v];
    }
    console.log(max);
}

function compareNumbers(a, b) {
  return a - b;
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));