"use strict"
String.prototype.add=function(b){
  var a=this;
  var L=Math.max(a.length,b.length);
  while(a.length<L){
    a='0'+a;
  }
  while(b.length<L){
    b='0'+b;
  }
  a=a.split('').reverse().join('');
  b=b.split('').reverse().join('');
  var c=[];
  for(let i=0;i<L;i++){
    c[i]=parseInt(a[i],10)+parseInt(b[i],10);
  }
  c[L]=0;
  for(let i=0;i<L+1;i++){
    c[i+1]+=(c[i]-c[i]%10)/10;
    c[i]=c[i]%10;
  }
  while(c[c.length-1]===0||c[c.length-1]!==c[c.length-1]){
    c.pop();
  }
  var str=c.reverse().join('');
  return str;
}

String.prototype.times=function(b){
  var a=this;
  var L=Math.max(a.length,b.length);
  while(a.length<2*L){//while1
    a='0'+a;
  }
  while(b.length<2*L){//while2
    b='0'+b;
  }
  
  a=a.split('').reverse().join('');
  b=b.split('').reverse().join('');
  var c=[];
  for(let i=0;i<2*L;i++){
    c[i]=0;
    for(let j=0;j<i+1;j++){
      c[i]+=parseInt(a[j],10)*parseInt(b[i-j],10);
    }
  }
  for(let i=0;i<2*L;i++){
    c[i+1]+=(c[i]-(c[i]%10))/10;
    c[i]=(c[i]%10);
  }
  while(c[c.length-1]===0||c[c.length-1]!==c[c.length-1]){
    c.pop();
  }
  var str=c.reverse().join('');
  return str;
}

String.prototype.isLargerThan=function(b){
  var a=this;
  if(a.length>b.length)return true;
  if(a.length<b.length)return false;
  for(let i=0;i<a.length;i++){
    var A=parseInt(a[i]),B=parseInt(b[i]);
    if(A>B)return true;
    if(A<B)return false;
  }
  return false;
}

function Main(input){
  var I=[],i=0;
  var checkNum=/^\d+/;
  var checkSpace=/ |\n/;
  while(input.length>0){
    if(input.match(checkNum)!==null){
      I[i]=input.match(checkNum)[0];
      input=input.replace(checkNum,"");    
      i++;
      continue;
    }
    input=input.replace(checkSpace,"");
    continue;
  }
  input=I;
  var N=parseInt(input[0]);
  var K=parseInt(input[1]);
  input.shift();
  input.shift();
  var A=[];
  for(let i=0;i<N;i++){
    A[i]=parseInt(input[i]);
  }
  var binaryA=[];
  for(let i=0;i<N;i++){
    binaryA[i]=A[i].toString(2);
    while(binaryA[i].length<41){
      binaryA[i]="0"+binaryA[i];
    }
  }//binaryA[i]は0詰め41桁の二進数
  var binaryKplusOne=(K+1).toString(2);
    while(binaryKplusOne.length<41){
      binaryKplusOne="0"+binaryKplusOne;
  }//binaryKplusOneは0詰め41桁の二進数

  var K_=[];
  var k=0;
  K_[0]=binaryKplusOne.indexOf("1");
  while(true){
    K_[k+1]=binaryKplusOne.indexOf("1",K_[k]+1);
    if(K_[k+1]===-1)break;
    k++;
  }
  K_.pop();
  
  var digSum=[];
  for(let i=0;i<41;i++){
    digSum[i]=0;
    for(let j=0;j<N;j++){
      digSum[i]+=(binaryA[j][i]==="1")?1:0;
    }
  }
  
  var X="";
  var counterMax='0';
  for(let i=0;i<K_.length;i++){
    X="";
    for(let j=0;j<K_[i];j++){
      X=X+""+binaryKplusOne[j];
    }
    X=X+"0";
    for(let j=K_[i]+1;j<41;j++){
      X=X+((digSum[j]>N-digSum[j])?"0":"1");
    }
    var counter='0';
    for(let j=0;j<41;j++){
      counter = counter.add(((X[40-j]==="0")?(digSum[40-j].toString(10)):(N-digSum[40-j]).toString(10)).times(Math.pow(2,j).toString(10)));
    }
    if(counter.isLargerThan(counterMax))counterMax=counter;
  }
  console.log(counterMax);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
