F=[1,1,2,3] while F[-1]<=10**15: F.append(F[-1]+F[-2]) ANS=0 A=[int(input()) for i in range(5)][::-1] for i in range(4): for j in range(i+1,6): for k in range(len(F)-(j-i)): if A[i:j]==F[k:k+j-i]: ANS=max(ANS,j-i) print(ANS)