#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
map<ll, bool> mp,cmp; int n;
ll calc(vector<int> v) {
	ll res = 0;
	rep(i, n) {
		res *= 10; res += v[i];
	}
	return res;
}
ll rev(ll x, int l, int r) {
	vector<int> v;
	rep(i, n) {
		v.push_back((int)(x % 10)); x /= 10;
	}
	reverse(v.begin(), v.end());
	reverse(v.begin() + l, v.begin() + r + 1);
	ll res = 0;
	rep(i, n) {
		res *= 10; res += v[i];
	}
	return res;
}
int main() {
	cin >> n;
	ll sta = 0; ll g = 0;
	rep(i, n) {
		int a; cin >> a; a--; g *= 10; g += a;
		sta *= 10; sta += i;
	}
	if (sta == g) {
		cout << 0 << endl; return 0;
	}
	queue<ll> q; q.push(sta); mp[sta] = true;
	queue<ll> p; p.push(g); cmp[g] = true;
	int c = 0; int sc = 0;
	bool fin = false;
	while (!fin) {
		int len = q.size();
		rep(j, len) {
			ll x = q.front(); q.pop();
			rep(i, n) {
				Rep(k, i + 1, n) {
					ll val = rev(x, i, k);
					if (cmp[val]) {
						cout << c + sc + 1 << endl; return 0;
					}
					if (!mp[val]) {
						mp[val] = true; q.push(val);
					}
				}
			}
		}
		c++;
		len = p.size();
		rep(j, len) {
			ll x = p.front(); p.pop();
			rep(i, n) {
				Rep(k, i + 1, n) {
					ll val = rev(x, i, k);
					if (mp[val]) {
						cout << c + sc + 1 << endl; return 0;
					}
					if (!cmp[val]) {
						cmp[val] = true; p.push(val);
					}
				}
			}
		}
		sc++;
	}
	//stop
	return 0;
}
