#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 minans = inf ;ans = 0 ;count = 0 ;pro = 1 F=[inf]*10**5; F[0]=1; F[1]=1 for i in range(2,10**5): F[i]=F[i-1]+F[i-2] if F[i]>=10**15: break A=[int(input()) for i in range(5)] A=A[::-1] k=bisect.bisect_left(F,A[0]) if A[0]==1: if A[1]==1: k=0 else: k=1 for i in range(5): # print(A[i],F[k+i],k) if A[i]==F[k+i]: count += 1 else: break print(count)