using System;

public class Program
{
    private int N;
    private int[] A, B;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        B = sc.IntArray();

        int l = 1 << N;

        var dp = new long[l, N];

        for (int i = 0; i < l; i++)
        {
            for (int j = 0; j < N; j++)
            {
                dp[i, j] = int.MaxValue;
            }
        }

        for (int mask = 0; mask < l - 1; mask++)
        {
            int bitCount = 0;
            for (int i = 0; i < N; i++)
            {
                if (C(mask, i))
                {
                    bitCount++;
                }
            }

            if (bitCount == 0)
            {
                for (int i = 0; i < N; i++)
                {
                    dp[mask | (1 << i), i] = 0;
                }
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    // iを追加
                    if (!C(mask, i))
                    {
                        int ii = (bitCount - i) % 2 == 0 ? A[i] : B[i];

                        // 一個前
                        long c = int.MaxValue;

                        // 前にある(iiより小さい)のにiより番号が大きいカード
                        int cnt = 0;

                        for (int j = 0; j < N; j++)
                        {
                            if (C(mask, j))
                            {
                                int jj = (bitCount - 1 - j) % 2 == 0 ? A[j] : B[j];
                                if (jj <= ii)
                                {
                                    c = Math.Min(c, dp[mask, j]);
                                }

                                if (i < j)
                                {
                                    cnt++;
                                }
                            }
                        }

                        int next = mask | (1 << i);
                        dp[next, i] = Math.Min(dp[next, i], c + cnt);
                    }
                }
            }
        }

        long ans = int.MaxValue;
        for (int i = 0; i < N; i++)
        {
            ans = Math.Min(ans, dp[l - 1, i]);
        }

        Console.WriteLine(ans == int.MaxValue ? -1 : ans);
    }

    bool C(int mask, int i)
    {
        return (mask & (1 << i)) > 0;
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

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

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 47712