program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,j
    integer(int32), allocatable:: b(:), te(:), ind(:)
    logical:: find
    read*, n
    allocate(b(n), te(n), ind(n))
    read*, b(:)

    do i=1,n
        ind(i) = i
    end do

    i=n

    do while(i>0)
        find=.false.
        do j=n,1,-1
            if (b(j)==ind(j)) then
                find=.true.
                te(i)=b(j)
                ind(j:) = ind(j:)-1
                i=i-1
                exit
            end if
        end do

        if (.not.find) then
            print'(i0)', -1
            stop
        end if
    end do

    do i=1,n
        print'(i0)', te(i)
    end do
end program name