program answer
  implicit none

  integer :: N, i

  read(*,*) N

  do i = 0, 10
     if(N==1000*i) then
        write(*,*) 0
        stop
     end if
     if(N>1000*i.and.N<1000*(i+1)) then
        write(*,*) 1000*(i+1)-N
        stop
     end if
  end do

  stop
 end program answer