The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.

There is a permutation p_i of numbers from 1 to 2n. You can make two types of operations. 

  1. Swap p_1 and p_2, p_3 and p_4, ..., p_{2n-1} and p_{2n}. 
  2. Swap p_1 and p_{n+1}, p_2 and p_{n+2}, ..., p_{n} and p_{2n}. 



The task is to find the minimal number of operations required to sort the given permutation.

The Knight was not that smart actually, but quite charming, so the princess asks you to help him to solve the King's task.

Input

The first line contains the integer n (1≤ n≤ 1000). The second line contains 2n integers p_i — the permutation of numbers from 1 to 2n.

Output

Print one integer — the minimal number of operations required to sort the permutation. If it is impossible to sort the permutation using these operations, print -1.

Examples

Input


3
6 3 2 5 4 1


Output


3


Input


2
3 4 2 1


Output


-1


Input


4
1 2 3 4 5 6 7 8


Output


0

Note

In the first example, you can sort the permutation in three operations: 

  1. Make operation 1: 3, 6, 5, 2, 1, 4. 
  2. Make operation 2: 2, 1, 4, 3, 6, 5. 
  3. Make operation 1: 1, 2, 3, 4, 5, 6. 
  #include<bits/stdc++.h>
            using namespace std;
            typedef long long int lli;
            #define fi(n) for(lli i=0;i<n;i++)
            #define fj(n) for(lli j=0;j<n;j++)
            #define pb push_back
            #define mp make_pair
            #define F first
            #define S second
            #define pii pair<lli,lli>
            #define MAX 1000001
            #define INF (int)1e18
            #define vii vector<lli>
            #define vip vector<pii> 
            #define pip pair<lli,pii>
            lli mod=1000000007;
            
            
           /* bool comp(pii a,pii b)
            {
                if(a.F==b.F){return a.S<b.S;}
                return a.F<b.F;
            }*/
            /*lli modexp(lli x,lli y) 
            { 
                if (y == 0) 
                    return 1; 
                lli p = modexp(x, y/2) % mod; 
                p = (p * p) % mod; 
              
                return (y%2 == 0)? p : (x * p) % mod; 
            }*/
            /*lli gcdext(lli a,lli b,lli *x,lli *y);
            lli modexpcop(lli a,lli m);
            lli modexpcop(lli a,lli m)   // a.x= 1 mod m  //a.x+b.y =gcd(a,b) extended
            {                            // for this b=m
                lli x,y;
                lli g=gcdext(a,m,&x,&y);
                if(g!=1)
                {
                    //inverse does not exists
                }
                else
                {
                    lli res=(x%m+m)%m;
                    return res;
                }
            }
            lli gcdext(lli a,lli b,lli *x,lli *y)
            {
                if(a==0)  //base case
                {
                    *x=0;*y=1;
                    return b;
                }
                lli x1,y1;
                lli g=gcdext(b%a,a,&x1,&y1);
                *x=y1-(b/a)*x1;
                *y=x1;
                return g;
            }*/
            /*vector<lli> v;
            vii v[8];
            lli sp[MAX];
            //bool b[MAX];
            void sieve()
            {
                for(lli i=0;i<MAX;i++)
                {
                    sp[i]=i;
                }
                for(int i=4;i<MAX;i+=2)
                {
                    sp[i]=2;
                }
                //v.pb(2);
                for(lli i=3;i*i<MAX;i++)
                {
                    if(sp[i]==i)
                    {
                        //v.pb(i);
                        for(lli j=i*i;j<MAX;j+=i)
                        {
                            if(sp[j]==j)
                            {
                                sp[j]=i;
                            }
                        }
                    }
                }
            }
            lli factorise(lli x)
            {
                set<lli> s;
                while(x!=1)
                {
                    s.insert(sp[x]);
                    x/=sp[x];
                }
                lli sz=s.size();
                return sz;
            }*/
        
            /*lli f[100001];
            void fib()
            {
                f[0]=1;f[1]=1;f[2]=2;
                for(lli i=3;i<=100000;i++)
                {
                    f[i]=f[i-1]%mod+f[i-2]%mod;
                    f[i]=f[i]%mod;
                }
            }*/
            
                
            void swap1(lli a[],lli n)
            {
                for(lli i=0;i<2*n;i+=2)
                {
                    swap(a[i],a[i+1]);
                }
            }
            void swap2(lli a[],lli n)
            {
                fi(n)
                {
                    swap(a[i],a[i+n]);
                }
            }
            bool chk(lli a[],lli n)
            {
                fi(2*n)
                {
                    if(i!=0 && a[i]-a[i-1]!=1)
                    {
                        return 0;
                    }
                }
                return 1;
            }
            int main()
            {
                ios_base::sync_with_stdio(false);
                cin.tie(NULL);
                cout.tie(NULL);
                lli t=1;
                //cin>>t;
                while(t--)
                {
                    lli n,f=0,cnt1=0,cnt2=0;
                    cin>>n;
                    lli a[2*n],b[2*n];
                    fi(2*n)
                    {
                        cin>>a[i];
                        b[i]=a[i];
                    }
                    while(1)
                    {
                        if(a[0]!=1)
                        {
                            if(f==0){swap1(a,n);}
                            else{swap2(a,n);}
                            cnt1++;
                        }
                        else{break;}
                        f=1-f;
                    }
                    f=0;
                    while(1)
                    {
                        if(b[0]!=1)
                        {
                            if(f==1){swap1(b,n);}
                            else{swap2(b,n);}
                            cnt2++;
                        }
                        else{break;}
                        f=1-f;
                    }
                    if(cnt1<=cnt2 && chk(a,n)){cout<<cnt1<<"\n";}
                    else if(cnt1>=cnt2 && chk(b,n)){cout<<cnt2<<"\n";}
                    else{cout<<-1<<"\n";}
                }
                return 0;
            }    