N = gets.to_i
array = gets.split.map(&:to_i)

if !array.include?(1)
    puts -1
elsif array == (1..N).to_a
    puts 0
else
    array = array.drop_while { |a| a != 1 }
    n = 2
    
    while !array.index(n).nil? do
        array = array.drop_while { |a| a != n }
        n += 1
    end
    
    puts N - n + 1
end