def func(n): if n in [1,2]: return 1 if memo[n] == 0: memo[n] = func(n-1)+func(n-2) return memo[n] A = [int(input()) for _ in range(5)] memo = [0 for _ in range(10**4)] i = 1 ans = 0 while 1: if func(i) == A[4-ans]: ans += 1 elif func(i) > A[0]: break i += 1 print(ans)