l,r,c = map(int,input().split()) if r - l > 2000: print(0) else: ans = 10**10 for i in range(l,r+1): ans = min(ans,(1000-i*c%1000)%1000) print(ans)