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