A = [int(input()) for _ in range(5)] A.reverse() ans = 0 f = [0, 1, 1, 2, 3] for i in range(100): if f[0] == A[0]: match = 1 for i in range(1, 5): if f[i] == A[i]: match += 1 else: break ans = max(ans, match) elif f[0] > A[0]: break f[0:4] = f[1:5] f[4] += f[2] print(ans)