program sample
    implicit none
  
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    if (mod(n,1000)==0)then
        wrITe(*,*)0
    else
    write(*,*) (n/1000+1)*1000-n
    end if
  
    stop
end program sample
  

