L, R, C = map(int, input().split()) if R - L > 1000: print(0) else: ans = min((-x*C) % 1000 for x in range(L, R+1)) print(ans)