      PROGRAM piyo
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      integer(prec) :: n
      
      read*,n
      
      print'(i0)',mod(100000-n,1000)
      
      stop
      !debugg
      
      
      
      END PROGRAM