#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define show(x) cerr << #x << " = " << x << endl;

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "sz:" << v.size() << "\n{";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "}\n";
    return os;
}


int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<int> S(N);
    for (int i = 0; i < N; i++) {
        S[i] = i + 1;
    }

    constexpr int MAX = 10;
    constexpr int HALF = (MAX - 1) / 2;

    vector<set<vector<int>>> former(HALF + 1);
    vector<set<vector<int>>> latter(HALF + 1);
    former[0].insert(A);
    latter[0].insert(S);

    for (int i = 0; i < HALF; i++) {
        for (const auto& V : former[i]) {
            for (int l = 0; l < N - 1; l++) {
                for (int r = l + 1; r < N; r++) {
                    auto v = V;
                    for (int k = 0; k < (r - l + 1) / 2; k++) {
                        swap(v[l + k], v[r - k]);
                    }
                    former[i + 1].insert(v);
                }
            }
        }
        for (const auto& V : latter[i]) {
            for (int l = 0; l < N - 1; l++) {
                for (int r = l + 1; r < N; r++) {
                    auto v = V;
                    for (int k = 0; k < (r - l + 1) / 2; k++) {
                        swap(v[l + k], v[r - k]);
                    }
                    latter[i + 1].insert(v);
                }
            }
        }
    }

    //    show(former);

    for (int i = 0; i < N - 1; i++) {
        if (i <= HALF) {
            if (former[i].find(S) != former[i].end()) {
                cout << i << endl;
                return 0;
            }
        } else {
            const int res = i - HALF;
            for (const auto& v : latter[res]) {
                if (former[HALF].find(v) != former[HALF].end()) {
                    cout << i << endl;
                    return 0;
                }
            }
        }
    }
    cout << N - 1 << endl;

    return 0;
}