{-
 - AOJ #1186: Integral Rectangles
 - nextrect (h,w) = (h',w')
 -   where (h',w') is the smallest wide integral rectangle
 -   bigger than (h,w).
 -}

import Control.Monad        -- unless
import Control.Applicative  -- <$>

-- Type of the integral rectangles
data IntRect = IR Int Int deriving Eq

instance Ord IntRect where
  compare (IR h w) (IR h' w')
    | h == h' && w == w'            = EQ
    | d < d' || (d == d' && h < h') = LT
    | otherwise                     = GT
    where diagSq h w = h^2 + w^2
          d  = diagSq h  w
          d' = diagSq h' w'

instance Show IntRect where
  show (IR h w) = (show h) ++ " " ++ (show w)

-- nextRect
nextRect :: IntRect -> IntRect
nextRect (IR h w) = minimum $
  map head [dropWhile (<= (IR h w)) [(IR h' w') | w'<-[h'+1..]] | h'<-[1..w]]
  -- (IR h w) < (IR w w+1) < (every wide rectangle whose height > w).

main :: IO ()
main = do
  [h,w] <- (map read . words) <$> getLine
  unless (h == 0 && w == 0) $ do
    putStrLn (show $ nextRect (IR h w))
    main  -- recursion