n = gets.to_i
s = [0] + gets.split.map(&:to_i)
t = (0..n).to_a

if s == t
    puts 0
    exit
end

f_queue = [s]
f_dist = {s => 0}

b_queue = [t]
b_dist = {t => 0}

min = nil
TUNING_PARAM = 3
loop do
    TUNING_PARAM.times do
        a = f_queue.shift
        l = 1
        l += 1 while a[l] == l
        r = n
        r -= 1 while a[r] == r
        (l..r).to_a.combination(2) do |i, j|
            b = a.dup
            (0..(j-i)/2).each do |k|
                x, y = i + k, j - k
                b[x], b[y] = b[y], b[x]
            end
            next if f_dist[b]
            f_dist[b] = f_dist[a] + 1
            if b_dist[b]
                min = f_dist[b] + b_dist[b]
                break
            end
            f_queue << b
        end
        break if min
    end
    break if min

    a = b_queue.shift
    (1..n).to_a.combination(2) do |i, j|
        b = a.dup
        (0..(j-i)/2).each do |k|
            x, y = i + k, j - k
            b[x], b[y] = b[y], b[x]
        end
        next if b_dist[b]
        b_dist[b] = b_dist[a] + 1
        if f_dist[b]
            min = f_dist[b] + b_dist[b]
            break
        end
        b_queue << b
    end
    break if min
end
p min