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