eval"N,K,*A="+`dd`.split*?,
*s=0;N.times{|i|s<<s[-1]+A[i]}
t=s.combination(2).map{|i,j|j-i}.sort.reverse
b=t[0].bit_length
(b-1).downto(0){|i|
  u=t.select{|x|x[i]>0}
  if u.size>=K
    t=u
  end
}
p t.reduce(:&)