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

int n;
set <vector<int>> used;
queue <pair<vector<int>, int>> Q;

vector <int> op1 (vector <int> & arr)
{
    vector <int> temp (2*n);
    for (int i=1, k = 0; i < 2*n; i += 2)
    {
        temp[k++] = arr[i];
        temp[k++] = arr[i-1];
    }
    return temp;
}

vector <int> op2 (vector <int> & arr)
{
    vector <int> temp (2*n);
    int k = 0;
    for (int i=n; i < 2*n; i++)
    {
        temp[k++] = arr[i];
    }
    for (int i=0; i < n; i++)
    {
        temp[k++] = arr[i];
    }
    return temp;
}

bool isSorted (vector <int> &arr)
{
    for (int i=1; i<2*n; i++)
    {
        if (arr[i] < arr[i-1])
            return 0;
    }
    return 1;
}

int bfs (vector <int> & arr)
{
    used.insert(arr);
    Q.push({arr, 0});
    while (!Q.empty())
    {
        if (isSorted(Q.front().first))
            return Q.front().second;

        vector <int> temp = op1(Q.front().first);
        if (used.find(temp) == used.end())
        {
            Q.push({temp, Q.front().second+1});
            used.insert(temp);
        }

        temp = op2(Q.front().first);
        if (used.find(temp) == used.end())
        {
            Q.push({temp, Q.front().second+1});
            used.insert(temp);
        }
        Q.pop();
    }
    return -1;
}

int main()
{
    cin >> n;
    vector <int> arr(2*n);
    for (int i=0; i<2*n; i++)
        cin >> arr[i];

    cout << bfs(arr);
    return 0;
}

/*

*/
