import Control.Applicative ((<$>))
import Control.Monad (replicateM, unless)

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, m] <- map read <$> words <$> getLine
  unless (n == 0 && m == 0) $ do
    solve m <$> replicateM n (readi B.readInt <$> B.getLine) >>= print
    main

solve :: Int -> [Int] -> Int
solve m xs = IS.findMax $ IS.unions [s1, s2, s3, s4]
  where s1 = IS.fromList xs
        s2 = IS.foldl' f IS.empty s1
        s3 = IS.foldl' f IS.empty s2
        s4 = IS.foldl' f IS.empty s3
        f s x =  IS.union s (IS.fromList (filter (<=m) (map (+x) xs)))

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

