PROGRAM MinMax
   IMPLICIT NONE
   
   INTEGER :: Minimum, Maximum
   INTEGER :: Count
   INTEGER :: Data

   Count = 0
   DO
      READ(*,*) Data
      IF ( Data < 0 ) EXIT
      Count = Count + 1
      WRITE(*,*) 'Data item # ', Count, ' = ', Data
      IF ( Count == 1 ) THEN
         Maximum = Data
         Minimum = Data
      ELSE 
         IF ( Data > Maximum ) Maximum = Data
         IF ( Data < Minimum ) Minimum = Data
      END IF
   END DO

   WRITE(*,*) 
   IF ( Count > 0 ) THEN
      WRITE(*,*) 'Found ' , Count, ' data items'
      WRITE(*,*) ' Maximum = ', Maximum
      WRITE(*,*) ' Minimun = ', Minimum 
   ELSE 
      WRITE(*,*) 'No data items found.'
   END IF

END PROGRAM MinMax   

