program noguchi_maisu
    integer n
    integer :: a = 0
    read *, n
    if(mod(n, 1000) == 0)then
        a = mod(n, 1000)
        print *, a
    else
        a = (n/1000 + 1)*1000-n
        print *, a
    end if
end program