import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Ord
import Data.Bits

main=do
    [n,k]<-map read.words<$>getLine::IO[Int]
    as<-unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ sol k as

sol k as = maximum $ map (foldl1 (.&.).take k) $ filter ((>=k).length) $ tails $ sortBy (flip compare) $ concatMap (scanl1 (+)) $ tails as
