import sys def input(): return sys.stdin.readline().rstrip() def main(): L, R, C = map(int, input().split()) R = min(R, L+2000) z = 999 for i in range(L, R+1): z = min(z, -i*C % 1000) print(z) if __name__ == '__main__': main()