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



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

rec(a)
