l, r, c = map(int, input().split()) if r - l >= 2000: print(0) else: ans = 1000 for i in range(l, r + 1): ans = min(ans, (-i * c) % 1000) print(ans)