#!/usr/bin/ruby n,m=gets.split.map(&:to_i) fib=[0,1] (2..n).each{|i|fib[i]=fib[i-1]+fib[i-2]} target=fib[n]-m r=0 n.downto(1){|i| if target>=fib[i] target-=fib[i] r+=1 end } p target==0 ? r : -1