while True:
try:
def function1(num):
for i in range(num,0,-1):
total=0
I=str(i)
for a in I:
if int(a)%2==1:
total+=1
if len(I)==total:
return i
break
def function2(x):
for i in range(x,10000000,1):
total=0
I=str(i)
for a in I:
if int(a)%2==1:
total+=1
if len(I)==total:
return i
break
N=int(input())
K2=function2(N)-N
K1=N-function1(N)
print(min(K1,K2))
except EOFError:
break