l, r, c = map(int, input().split()) r = min(l + 999, r) ans = 1000 for x in range(l, r + 1): rest = 1000 * ((x * c + 999) // 1000) - x * c ans = min(ans, rest) print(ans)