//
//  main.cpp
//  AOJ
//
//  Created by user on 2014/06/01.
//  Copyright (c) 2014年 user. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cstring>
#include <map>
#include <cstdio>
using namespace std;

//const int SIZE = 3628810;
typedef long long ll;
typedef pair< vector<int>, ll > Pack;


ll pw[12];
inline void init(){
    pw[0] = 1;
    for(int i=1;i<12;i++)pw[i] = pw[i-1] * 10;
}


ll getPermId(const vector<int>& v){
    /*
    const int N = (int)v.size();
    
    int fact = 1;
    int res = 0;
    
    for(int i=N-1;i>=0;i--){
        for(int j=i+1;j<N;j++){
            if(v[j] < v[i]){
                res += fact;
            }
        }
        fact *= (N - i);
    }
    
    return res;*/
    
    ll res = 0;
    for(int i=0;i<v.size();i++){
        res += pw[i] * v[i];
    }
    
    return res;
}

map<ll, int> dist[2];
vector<Pack> Queue[2];

int bfs(const vector<int>& start, const vector<int>& goal){
    const int N = (int)start.size();
    const ll startId = getPermId(start);
    const ll goalId  = getPermId(goal);
    
    if(startId == goalId){
        return 0;
    }
    
    int curr = 0, next = 1;
    
    dist[curr][startId] = 0;
    dist[next][goalId]  = 0;
    
    Queue[curr].push_back(make_pair(start, startId));
    Queue[next].push_back(make_pair(goal,  goalId));
    
    for(;;){
        vector<Pack> nextQueue;
        for(int i=0;i<Queue[curr].size();i++){
            Pack &pack = Queue[curr][i];
            
            vector<int> &perm = pack.first;
            ll permId = pack.second;
            int nowCost = dist[curr][permId];
            
            /*for(int s=0;s<N;s++)for(int t=s+1;t<N;t++){
                reverse(perm.begin() + s, perm.begin() + t + 1);
            
                int nextPermId = getPermId(perm);
                if(dist[curr][nextPermId] == -1){
                    dist[curr][nextPermId] = nowCost + 1;
                
                    if(dist[next][nextPermId] != -1){
                        return dist[curr][nextPermId] + dist[next][nextPermId];
                    } else {
                        nextQueue.push_back(make_pair(perm, nextPermId));
                    }
                }
                
                reverse(perm.begin() + s, perm.begin() + t + 1);
            }*/
            
            for(int s=0;s<N;s++){
                for(int d=1;d<=2;d++){
                    ll nextPermId = permId;
                    
                    int S = s;
                    int T = s + d;
                    
                    while(S >= 0 && T < N){
                        nextPermId -= pw[S] * perm[S];
                        nextPermId += pw[S] * perm[T];
                        nextPermId -= pw[T] * perm[T];
                        nextPermId += pw[T] * perm[S];
                        
                        swap(perm[S], perm[T]);
            
                        if(!dist[curr].count(nextPermId)){
                            dist[curr][nextPermId] = nowCost + 1;
                            
                            if(dist[next].count(nextPermId)){
                                return dist[curr][nextPermId] + dist[next][nextPermId];
                            } else {
                                nextQueue.push_back(make_pair(perm, nextPermId));
                            }
                        }
                        
                        --S;
                        ++T;
                    }
                    
                    
                    
                    S = s;
                    T = s + d;
                    
                    while(S >= 0 && T < N){
                        swap(perm[S], perm[T]);
                        
                        --S;
                        ++T;
                    }
                }
            }
        }
        Queue[curr].swap(nextQueue);
        
        swap(curr, next);
    }
    
    return 1;
}

int main(){
    init();
    
    int N;
    scanf("%d", &N);
    
    vector<int> start(N);
    for(int i=0;i<N;i++){
        scanf("%d", &start[i]);
        --start[i];
    }
    
    vector<int> goal = start;
    sort(goal.begin(), goal.end());
    
    int res = bfs(start, goal);
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 70648