L=int(input()) R=int(input()) C=int(input()) t=1000 a=t b=(L*C)%t for i in range(L,R+1): if b==0: print(0) exit(1) a=min(a,t-b) b=(b+C)%t print(a)