main = interact $ show.solve.(map read).words
solve (a:b:[]) = ok a b $ max (rev 8 a) (rev 10 b)
rev::Int->Int->Int
rev t = flip div t <$> (*) 100
tax::Int->Int->Int
tax t = flip div 100 <$> (*) t
ok::Int->Int->Int->Int
ok a b x
    | tax 8 x == a && tax 10 x == b = x
    | otherwise = -1