-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU main = print . solve . map read . words =<< getLine solve (n:m:_) = g rf dif 0 where f = take n fib rf = reverse f (fn,_) = head rf dif = fn - m g _ 0 p = if n >= p + 3 then p else (-1) g [] _ _ = (-1) g ((x,s):xs) d p | s < d = (-1) | x > d = g xs d p | otherwise = case (g xs d p, g xs (d - x) (p + 1)) of ((-1), b ) -> b (a, (-1)) -> a (a, b ) -> minimum [a, b] fib = [(1,1), (1,2)] ++ [(ab, ab + s) | x <- [0..], let ((a,_):(b,s):_) = drop x fib, let ab = a + b]