L,R,C = map(int, input().split()) while R-L > 1: mid = (L+R)//2 if mid*C <= 1000: L = mid else: R = mid print(1000 - L*C)