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