#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, a[10];

int main(){
	cin >> n;
	rep(i, n) cin >> a[i];
	
	map<ll, int> m;
	set<ll> s;
	queue<pair<int, ll> > q;
	ll t = 0, g = 0;
	rep(i, n){
		t *= 16, t += a[i];
		g *= 16, g += i + 1;
	}
	q.push(mp(0, g));
	m[g] = 0;
	
	while(!q.empty()){
		ll t = q.front().second;
		int c = q.front().first; q.pop();
		
		rep(i, n) a[n - 1 - i] = t % 16, t /= 16;
		rep(i, n) for(int j = i + 1; j < n; j++){
			reverse(a + i, a + j + 1);
			ll h = 0;
			rep(k, n) h *= 16, h += a[k];
			if(!m.count(h)){
				m[h] = c + 1;
				if(c < 3) q.push(mp(c + 1, h));
			}
			reverse(a + i, a + j + 1);
		}
	}
	if(m.count(t)){
		cout << m[t] << endl;
		return 0;
	}
	q.push(mp(0, t));
	s.insert(t);
	
	while(!q.empty()){
		ll t = q.front().second;
		int c = q.front().first; q.pop();
		
		rep(i, n) a[n - 1 - i] = t % 16, t /= 16;
		rep(i, n) for(int j = i + 1; j < n; j++){
			reverse(a + i, a + j + 1);
			ll h = 0;
			rep(k, n) h *= 16, h += a[k];
			if(m.count(h)){
				cout << c + 1 + m[h] << endl;
				return 0;
			}
			if(c < 3 && !s.count(h)){
				s.insert(h);
				q.push(mp(c + 1, h));
			}
			reverse(a + i, a + j + 1);
		}
	}
	cout << 9 << endl;
	
	return 0;
}