program main
integer :: N, i, j
integer,allocatable :: a(:), b(:), ans(:)
read(*, *)N
allocate(a(N))
allocate(ans(N))
read(*, *)a

do i = N, 1, -1
    do j = i, 1, -1
        if (a(j) == j)then
            ans(i) = j
            exit
        endif
    enddo
    if(j == 0)then
        write(*, '(i0)') -1
        stop
    endif
    b = [a(1:j - 1), a(j + 1: i)]
    a = b
enddo

write(*, '(*(i0, :, /))') ans


end program main