program main
    implicit none
    integer n
    read(*,*)n
    do
        if(n>=1000)then
            n=n-1000
            cycle
        else 
            exit
        endif
    enddo
    write(*,*)n

end program main
