#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H(vector<int>&a){
    int ret=0,f=1;
    for(int i=a.size()-1;i>=0;i--){
        int cnt=0;
        for(int j=i;j<a.size();j++)if(a[i]>a[j])cnt++;
        ret+=f*cnt;
        f*=a.size()-i;
    }
    return ret;
}

void bfs(vint A,vint &cost){
    fill(all(cost),1001001001);
    cost[H(A)]=0;
    queue<vint>que;
    que.push(A);
    while(que.size()){
        vint a=que.front();
        que.pop();
        int h0=H(a);
        if(cost[h0]==4)break;
        for(int i=0;i<a.size();i++){
            for(int j=i+1;j<=a.size();j++){
                reverse(a.begin()+i,a.begin()+j);
                int h=H(a);
                if(cost[h]==1001001001){
                    cost[h]=cost[h0]+1;
                    que.push(a);
                }
                reverse(a.begin()+i,a.begin()+j);
            }
        }
    }
}

signed main(){
    int N;cin>>N;
    vector<int>A(N);
    rep(i,N)cin>>A[i];

    vector<int>B(N);
    rep(i,N)B[i]=i+1;

    vector<int>costA(3628800),costB(3628800);
    bfs(A,costA);bfs(B,costB);

    int ans=9;
    rep(i,3628800)chmin(ans,costA[i]+costB[i]);
    cout<<ans<<endl;
    return 0;
}