def solve(): L,R,C=map(int,input().split()) ans=10**9 for x in range(L, min(R,L+1000)+1): cost=C*x q=(cost+999)//1000 ans=min(ans, 1000*q-cost) return ans #================================================== print(solve())