def Fib(n): a, b = 0, 1 if n == 1: return a elif n == 2: return b else: for _ in range(n-2): a, b = b, a + b return b fib = [Fib(n) for n in range(1, 100)] del fib[0] arr = [int(input()) for _ in range(5)][::-1] ans_1 = 0 check = [1,2,3,5,8] for i in range(5): if arr[i] == check[i]: ans_1 += 1 else: break ans = 0 if arr[0] in fib: ans += 1 for i in range(1,5): if arr[i] == fib[fib.index(arr[0])+i]: ans += 1 else: break print(max(ans,ans_1))