#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

void rec(vector<int> &x, map<vector<int>, int> &mp)
{
  queue<vector<int>> que;
  que.emplace(x);
  while (!que.empty())
  {
    vector<int> a = que.front();
    que.pop(); 
    int cou = mp[a];
    if(cou == 4) continue;
    for (int i = 0; i < a.size(); i++)
    {
      for (int j = i + 1; j < a.size(); j++)
      {
        reverse(a.begin() + i, a.begin() + j + 1);
        auto ite = mp.find(a);
        if (ite == mp.end())
        {
          mp[a] = cou + 1;
          if(cou + 1 < 4)
          que.emplace(a);
        }
        reverse(a.begin() + i, a.begin() + j + 1);
      }
    }
  }
}

int n;
int main()
{
  cin >> n;
  vector<int> a(n);
  vector<int> sorted(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i]--;
  }
  for (int i = 0; i < n; i++)
  {
    sorted[i] = i;
  }

  map<vector<int>, int> mp_sorted, mp_a;
  mp_sorted[sorted] = 0;
  mp_a[a] = 0;
  rec(sorted, mp_sorted);
  rec(a, mp_a);
  int result = n - 1;
  do
  {
    auto ite = mp_sorted.find(sorted);
    auto ite2 = mp_a.find(sorted);
    if (ite != mp_sorted.end() && ite2 != mp_a.end())
    {
      result = min(result, ite->second + ite2->second);
    }
  } while (next_permutation(sorted.begin(), sorted.end()));
  cout << result << endl;
}

