from collections import deque N = int(input()) if N==1: print(1) else: flag = -1 for k in range(2,1000+1): A = [0]*k A[0] = 1 A = deque(A) a = sum(A) for i in range(1,1000+1): if a==N: flag = k break elif a>N:break b = A.pop() A.appendleft(a) a -= b a += A[0] if flag>0:break print(flag)