_=gets()
a=gets.split.map(&:to_i)

def rec(x)
    if x.size ==0
        return true
    end
    (0...x.size).to_a.reverse.each{|i|
        if x[i] <(i+1)
            return false
        end
        if x[i]==(i+1)
            r=rec(x.values_at(0...i,(i+1)...x.size))
            if r
                p (i+1)
                return true
            end
        end
    }
    return false
end

r=rec(a)
p -1 if !r

