#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[10];

int encode(int x[10], int n) {
  int res = 0;
  REP(i,n-1) {
    res = 10 * res + x[i];
  }
  return res;
}

void decode(int x[10], int n, int code) {
  int bit = 0;
  for (int i=n-2; i>=0; --i) {
    x[i] = code%10;
    bit |= 1<<x[i];
    code /= 10;
  }
  REP(i,n) if (!(bit>>i&1)) x[n-1] = i;
}

int now[10];

int main() {
  int n;
  cin >> n;
  REP(i,n) {
    cin >> a[i];
    --a[i];
  }
  queue<int> Q;
  int start = encode(a,n);
  Q.push(start);
  map<int, int> mp;
  mp[start] = 0;
  while(!Q.empty()) {
    int p = Q.front(); Q.pop();
    decode(now, n, p);
    int d = mp[p];
    REP(i,n) {
      REP(j,i) {
        reverse(now+j, now+i+1);
        int next = encode(now,n);
        if (mp.count(next) == 0) {
          mp[next] = d+1;
          if (d<4) {
            Q.push(next);
          }
        }
        reverse(now+j, now+i+1);        
      }
    }
  }
  REP(i,n) now[i]=i;
  start = encode(now,n);
  Q.push(start);
  map<int,int> mp2;
  mp2[start] = 0;
  int ans = INF;
  
  while(!Q.empty()) {
    int p = Q.front(); Q.pop();
    decode(now, n, p);
    int d = mp2[p];

    if (mp.count(p)) {
      ans = min(ans, mp[p] + mp2[p]);
    }
    if (d == 4) continue;
    REP(i,n) {
      REP(j,i) {
        reverse(now+j, now+i+1);
        int next = encode(now,n);
        if (mp2.count(next) == 0) {
          mp2[next] = d+1;
          Q.push(next);
        }
        reverse(now+j, now+i+1);        
      }
    }
  }
  if (ans == INF) {
    cout << 9 << endl;
  } else {
    cout << ans << endl;
  }
}