def fib(dp, n): dp[0] = 0 dp[1] = 1 for i in range(2,n+1): dp[i] = dp[i-1] + dp[i-2] return dp def my_index_multi(l, x): return [i for i, _x in enumerate(l) if _x == x] def main(): A = [int(input()) for _ in range(5)] dp = [-1] * 10001 dp = fib(dp, 5000) if A[4] == 0: print(0) exit() ans = 0 if A[4] in dp: indexs = my_index_multi(dp, A[4]) for index in indexs: if dp[index+1] == A[3]: if dp[index+2] == A[2]: if dp[index+3] == A[1]: if dp[index+4] == A[0]: ans = max(ans, 5) else: ans = max(ans, 4) else: ans = max(ans, 3) else: ans = max(ans, 2) else: ans = max(ans, 1) print(ans) if __name__ == "__main__": main()