#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU def gs(); gets.chomp; end def gi(); gets.to_i; end def gss(); gets.chomp.split; end def gis(); gss.map(&:to_i); end N, M = gis def rec(xs,i,d,p) return p if d == 0 return -1 if i >= xs.size x, s = xs[i] return -1 if s < d return rec(xs,i+1,d,p) if x > d r1 = rec(xs,i+1,d,p) r2 = rec(xs,i+1,d-x,p+1) return r2 if r1 < 0 return r1 if r2 < 0 [r1, r2].min end def fibs(n) f = [1, 1] (2...n).each do |i| f << f[i - 1] + f[i - 2] end fs = [[1,1]] (1...f.size).each do |i| fs << [f[i], f[i] + fs[i-1][1]] end fs.reverse end def solve(n,m) f = fibs(n) rec(f[2..-1], 0, f[0][0] - m, 0) end p solve(N,M)