#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n;
struct A{
	int a[10];
	bool operator<(A a_) const {
		rep(i,n){
			if(a_.a[i] < this->a[i])return true;
			if(a_.a[i] > this->a[i])return false;
		}
		return false;
	}
	bool operator==(A a_) const {
		rep(i,n){
			if(a_.a[i] != this->a[i])return false;
		}
		return true;
	}
};

set<pair<A,int>> S;

A R(A x,int i,int j){
	A ret = x;
	for(int k = i ; k <= j ; k ++){
		ret.a[k] = x.a[i+j-k];
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	
	A a; rep(i,n)a.a[i] = i;
	S.insert(pair<A,int>(a,0));
	rep(ppp,4){
		for(set<pair<A,int>>::iterator itr = S.begin() ; itr != S.end() ; itr ++){
			if(itr->sc != ppp)continue;
			rep(i,n){
				for(int j = i+1 ; j < n ; j ++){
					a = R(itr->fr,i,j);
					if(!(S.lower_bound(pair<A,int>(a,0))->fr == a)){
						S.insert(pair<A,int>(a,ppp+1));
					}
				}
			}
		}
		//cout << ppp << " " << S.size() << endl;
	}
	
	rep(i,n){
		int aa;
		scanf("%d",&aa);
		a.a[i] = aa-1;
	}
	
	int ret = n-1;
	for(set<pair<A,int>>::iterator itr = S.begin() ; itr != S.end() ; itr ++){
		A b;
		rep(i,n)b.a[i] = a.a[itr->fr.a[i]];
		set<pair<A,int>>::iterator it = S.lower_bound(pair<A,int>(b,0));
		if(it->fr == b)ret = min ( ret , itr->sc + it->sc );
	}
	cout << ret << endl;
}