#encoding=utf-8
import sys
N=int(sys.stdin.readline().strip("\n"))
if N==0 or N==1:
print 0
else:
fibo=[]
fibo.append(0)
fibo.append(1)
while True:
curr=fibo[-1]+fibo[-2]
if curr<N:
fibo.append(curr)
else:
print min( N-fibo[-1],curr-N )
break