#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;

  vector<int> fact(n+1);
  fact[0]=1;
  for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;

  vector<int> diff(1<<n,0),num(1<<n,0);
  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if(i&(1<<j)){
        diff[i]+=fact[n-j-1];
        num[i]++;
      }
    }
  }

  vector<int> a(n),b(n);
  for(int i=0;i<n;i++) cin >> a[i];

  int start=0;
  int count;
  for(int i=1;i<n;i++){
    count=0;
    for(int j=0;j<n;j++){
      if(a[j]==i){
        start+=count*fact[n-i];
        break;
      }else if(a[j]>i){
        count++;
      }
    }
  }

  vector<int> dist(fact[n],-1);
  dist[start]=0;
  queue<int> bfs;
  bfs.push(start);
  int now,next,nt,dbg;
  while(!bfs.empty()){
    now=nt=bfs.front();
    bfs.pop();
    for(int i=0;i<n;i++) a[i]=-1;
    for(int i=0;i<n;i++){
      count=nt/fact[n-i-1];
      nt-=count*fact[n-i-1];
      for(int j=0;j<n;j++){
        if(a[j]<0){
          if(count==0){
            a[j]=i;
            break;
          }
          count--;
        }
      }
    }
    for(int i=1;i<n-1;i++){
      count=(1<<a[i]);
      next=now;
      for(int j=1;j<=min(i,n-i-1);j++){
        count+=(1<<a[i+j])+(1<<a[i-j]);
        next+=num[count&((1<<n)-(1<<(a[i-j]+1)))]*fact[n-a[i-j]-1]-num[count&((1<<n)-(1<<(a[i+j]+1)))]*fact[n-a[i+j]-1];
        if(a[i+j]>a[i-j]){
          next+=diff[count&((1<<a[i+j])-(1<<(a[i-j]+1)))];
        }else{
          next-=diff[count&((1<<a[i-j])-(1<<(a[i+j]+1)))];
        }
        if(dist[next]==-1){
          dist[next]=dist[now]+1;
          bfs.push(next);
        }
      }
    }
    for(int i=1;i<n;i++){
      count=0;
      next=now;
      for(int j=1;j<=min(i,n-i);j++){
        count+=(1<<a[i+j-1])+(1<<a[i-j]);
        next+=num[count&((1<<n)-(1<<(a[i-j]+1)))]*fact[n-a[i-j]-1]-num[count&((1<<n)-(1<<(a[i+j-1]+1)))]*fact[n-a[i+j-1]-1];
        if(a[i+j-1]>a[i-j]){
          next+=diff[count&((1<<a[i+j-1])-(1<<(a[i-j]+1)))];
        }else{
          next-=diff[count&((1<<a[i-j])-(1<<(a[i+j-1]+1)))];
        }
        if(dist[next]==-1){
          dist[next]=dist[now]+1;
          bfs.push(next);
        }
      }
    }
    if(dist[0]!=-1){
      cout << dist[0] << endl;
      return 0;
    }
  }
  return 0;
}

