l, r, c = io.read("*n", "*n", "*n") r = math.min(r, l + 1000) ans = 999LL for i = l, r do z = (1LL * i * c) % 1000LL z = 1000LL - z if z == 1000LL then z = 0LL end if z < ans then ans = z end end ans = tostring(ans):gsub("LL", "") print(ans)