import sys

key=int(sys.stdin.readline())

def fb(i):

    if i==0:
        return 0
    if i==1:
        return 1
    else:
        return fb(i-1)+fb(i-2)

l=[]

for i in range(20):
    l.append(fb(i))



i=1

while fb(i)<key:
    i=i+1
max1=fb(i)
min1=fb(i-1)

if key in l:
    print(0)
else:
    print(min(abs(key-min1),abs(key-max1)))