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