fib = [1] data = 1 while data <= 10 ** 15: fib.append(data) data = fib[-2] + fib[-1] A = [int(input()) for i in range(5)][::-1] ans = 0 for i in range(len(fib)): for j in range(5): if i + j >= len(fib): break if fib[i + j] == A[j]: ans = max(ans, j + 1) else: break print(ans)