L,R,C=map(int,input().split()) ANS=999 for i in range(L,min(R,L+10**6)+1): ANS=min(ANS,(1000-i*C%1000)%1000) print(ANS)