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