l,r,c=map(int,input().split()) res=1001 for i in range(l,min(l+1000,r+1)): res=min(res,(-i*c)%1000) print(res)