
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static Scanner sc = new Scanner();
    public static void Main(){
        var n = sc.NextInt();
        var list = sc.NextIntList().ToList();

        var ret = 0;
        var q = new List<List<int>>();
        q.Add(list);
        
        while(true){
            var next = new List<List<int>>();
            foreach(var l in q){
                if(Solved(l)){
                    Console.WriteLine(ret);
                    return;
                }
                
                for(var i = 0; i < n - 1; ++i){
                    next.Add(Swap(l, i).ToList());
                }
            }
            
            q = next;
            ++ret;
        }
    }
    

    public static bool Solved(List<int> list){
        for(var i = 0; i < list.Count; ++i){
            if(list[i] == i + 1) return false;
        }
        return true;
    }
    
    public static IEnumerable<int> Swap(List<int> list, int i){
        for(var j = 0; j < list.Count; ++j){
            if(j == i) {
                yield return list[i + 1];
            } else if(j - 1 == i) {
                yield return list[i];
            } else {
                yield return list[j];
            }
        }
    }
}

public class Scanner{
    private string line;
    private string[] token;
    private int cursole = 0;
    
    public string ReadLine(){
        line = Console.ReadLine();
        token = line.Split(' ');
        cursole = 0;
        return line;    
    }
    
    public string Next(){
        if(token == null) ReadLine();
        if(token.Length <= cursole) ReadLine();
        var ret = token[cursole];
        ++cursole;
        return ret;
    }

    public IEnumerable<double> NextDoubleList(){
        return NextList().Select(s => Double.Parse(s));
    }

    public int NextInt(){return Int32.Parse(Next());}
    
    public long NextLong(){return Int64.Parse(Next());}

    public double NextDouble(){return Double.Parse(Next());}

    public IEnumerable<string> NextList(){
        ReadLine();
        cursole = Int32.MaxValue;
        return token;
    }
    
    public IEnumerable<int> NextIntList(){
        return NextList().Select(s => Int32.Parse(s));
    }
}

public static class Extension{
    public static IEnumerable<int> To(this int from, int to){
        return Enumerable.Range(from, to);
    }

    public static void Times(this int times, Action<int> action){
        0.To(times).ToList().ForEach(x => action(x));
    }
}