import Control.Monad import System.IO import Data.List child [] n = [] child (x:xs) n = child xs n ++ (if 2*x+1<=n then [2*x,2*x+1] else if 2*x<=n then [2*x] else []) get [] p = [] get (x:xs) p = (get xs p) ++ [p!!(x-1)] solve [] p n = [] solve xs p n = [maximum (get xs p)] ++ solve (child xs n) p n readInts :: IO [Int] readInts = fmap (map read.words) getLine main :: IO () main = do x <- readInts y <- readInts putStr (intercalate " " (map show (solve [1] y (x!!0))))