l, r, c = [int(i) for i in input().split(" ")] print(min(map(lambda x: ((x*c // 1000 + 1) * 1000 - x*c) % 1000, range(l, r+1))))