#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<vector<vector<char> >,int> P;
const long long int MOD = 1000000007;
const int INF = 1000000000;

int n;
int num[11], tmp[11];
unordered_map<ll, int> m;
unordered_map<ll, int> mm;
queue<ll> que;

int main(){
    cin >> n;
    ll st = 0;
    rep(i,n){
        int x;
        cin >> x;
        if(x == 10){
            st = st*100+x;
        } else{
            st = st*10+x;
        }
    }
    que.push(st);
    m[st] = 0;
    while(!que.empty()){
        ll p = que.front();
        ll q = p;
        que.pop();
        int now = 0;
        while(p){
            if(p%10 == 0){
                num[n-now] = 10;
                p /= 100;
            } else{
                num[n-now] = p%10;
                p /= 10;
            }
            now++;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++) tmp[j] = num[j];
            for(int j = 1; j <= n; j++){
                if(i-j <= 0 || i+j > n) break;
                swap(tmp[i-j],tmp[i+j]);
                ll add = 0;
                for(int k = 1; k <= n; k++){
                    if(tmp[k] == 10){
                        add = add*100+10;
                    } else{
                        add = add*10+tmp[k];
                    }
                }
                if(m.count(add)) continue;
                m[add] = m[q]+1;
                if(m[add] < 5) que.push(add);
            }
        }
        for(int i = 1; i < n; i++){
            int ii = i+1;
            for(int j = 1; j <= n; j++) tmp[j] = num[j];
            for(int j = 0; j <= n; j++){
                if(i-j <= 0 || ii+j > n) break;
                swap(tmp[i-j],tmp[ii+j]);
                ll add = 0;
                for(int k = 1; k <= n; k++){
                    if(tmp[k] == 10){
                        add = add*100+10;
                    } else{
                        add = add*10+tmp[k];
                    }
                }
                if(m.count(add)) continue;
                m[add] = m[q]+1;
                if(m[add] < 5) que.push(add);
            }
        }
    }
    while(!que.empty()) que.pop();
    ll en = 0;
    for(int i = 1; i <= n; i++){
        if(i == 10){
            en = en*100+i;
        } else{
            en = en*10+i;
        }
    }
    que.push(en);
    if(m.count(en)){
        cout << m[en] << endl;
        return 0;
    }
    mm[en] = 0;
    while(!que.empty()){
        ll p = que.front();
        ll q = p;
        if(m.count(q)){
            cout << m[q]+mm[q] << endl;
            return 0;
        }
        que.pop();
        int now = 0;
        while(p){
            if(p%10 == 0){
                num[n-now] = 10;
                p /= 100;
            } else{
                num[n-now] = p%10;
                p /= 10;
            }
            now++;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++) tmp[j] = num[j];
            for(int j = 1; j <= n; j++){
                if(i-j <= 0 || i+j > n) break;
                swap(tmp[i-j],tmp[i+j]);
                ll add = 0;
                for(int k = 1; k <= n; k++){
                    if(tmp[k] == 10){
                        add = add*100+10;
                    } else{
                        add = add*10+tmp[k];
                    }
                }
                if(mm.count(add)) continue;
                mm[add] = mm[q]+1;
                if(mm[add] < 5) que.push(add);
            }
        }
        for(int i = 1; i < n; i++){
            int ii = i+1;
            for(int j = 1; j <= n; j++) tmp[j] = num[j];
            for(int j = 0; j <= n; j++){
                if(i-j <= 0 || ii+j > n) break;
                swap(tmp[i-j],tmp[ii+j]);
                ll add = 0;
                for(int k = 1; k <= n; k++){
                    if(tmp[k] == 10){
                        add = add*100+10;
                    } else{
                        add = add*10+tmp[k];
                    }
                }
                if(mm.count(add)) continue;
                mm[add] = mm[q]+1;
                if(mm[add] < 5) que.push(add);
            }
        }
    }
}

Measured memory_bytes: 75272