L, R, C = map(int, input().split()) ans = 1000 for i in range(L, min(L + 1010, R + 1)): ans = min(ans, (-C * i) % 1000) print(ans)