L, R, C = map(int, input().split()) if R - L < 1000: print(min([(-i * C) % 1000 for i in range(L, R + 1)])) else: print(0)