/*
TASK: round
LANG: C
*/

#include <stdio.h>

int i, j, n, first[2048], second[2048], res=4096, bla[4096];

void input()
{
  scanf("%d", &n);
  for(i = 0; i < n; i++)
  {
    scanf("%d", &first[i]);
    first[i]--;
  }
  for(i = 0; i < n; i++)
  {
    scanf("%d", &second[i]);
    second[i]--;
  }
}

void check(int masa[4096])
{
  int pyrvi=0, vtori=0, a[4096], count=0, human, temp1, temp2;
  for(i = 0; i < 2*n; i++)
    a[i] = 0;

  for(i = 0; i < 2*n; i++)
  {
    temp1 = temp2 = 0;
    
    if(masa[i] == 1)
    {
      human = first[pyrvi++];
      
      for(j = 0; j < human; j++)
        if(a[j])
          temp1++;

      for(j = 2*n-1; j > human; j--)
        if(a[j])
          temp2++;
      
      if(temp1 > temp2)
        count += temp2;
      else
        count += temp1;
    }
    else
    {
      human = second[vtori++];

      if(human < n)
      {
        for(j = n-1; j > human; j--)
          if(a[j])
            temp1++;
            
        for(j = 0; j < human; j++)
          if(a[j])
            temp2++;
        for(j = n; j < 2*n; j++)
          if(a[j])
            temp2++;
      }
      else
      {
        for(j = n; j < human; j++)
          if(a[j])
            temp1++;

        for(j = 0; j < n; j++)
          if(a[j])
            temp2++;
        for(j = 2*n-1; j > human; j--)
          if(a[j])
            temp2++;
      }
      
      if(temp1 > temp2)
        count += temp2;
      else
        count += temp1;
    }
    a[human] = 1;
  }
  if(res > count)
    res = count;
}

void rec(int f, int s, int taken[4096])
{
  if(f < n)
  {
    taken[f+s] = 1;
    rec(f+1, s, taken);
  }
  
  if(s < n)
  {
    taken[f+s] = 2;
    rec(f, s+1, taken);
  }

  if(f + s == 2*n)
    check(taken);
}

int main()
{
  input();

  rec(0, 0, bla);

  printf("%d\n", res);
  return 0;
}

