#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<short> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int n;

map<vi, short> bfs(vi v)
{
	map<vi, short> mp;
	queue<vi> que;
	que.push(v); mp[v] = 0;
	while (que.size())
	{
		vi tmp = que.front();
		que.pop();
		int t = mp[tmp];
		if (t >= (n-1) / 2) continue;
		REP(i, n)REP(j, i)
		{
			vi nx = tmp;
			reverse(nx.begin() + j, nx.begin() + i + 1);
			if (mp.find(nx) != mp.end()) continue;
			else
			{
				mp[nx] = t + 1;
				que.push(nx);
			}
		}
	}
	return mp;
}

signed main()
{
	cin >> n;
	vi a(n), b;
	REP(i, n) cin >> a[i];
	b = a;
	sort(ALL(b));
	auto mp1 = bfs(a);
	auto mp2 = bfs(b);
	int ans = n - 1;
	for (auto it = mp1.begin(); it != mp1.end(); it++)
	{
		if (mp2.find(it->first) != mp2.end()) chmin(ans, it->second + mp2[it->first]);
	}
	cout << ans << endl;
	return 0;
}