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 = foldl1 (.&.) $ filter (/=0) $ unfoldr (f k) (2^40, ss)
    where
        ss = sortBy (flip compare) $ concatMap (scanl1 (+)) $ tails as

f k (bm,ss)
    | length ss < k = Nothing
    | bm == 0 = Nothing
    | all (\s-> s .&. bm /= 0) ks = Just(bm, (bm`div`2, ss))
    | otherwise = Just(0, (bm`div`2, dropWhile (\s-> s .&. bm /=0) ss))
    where
        ks = take k ss
