local mmi = math.min
local inf = 1000000007
local n = io.read("*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = io.read("*n")
end
for i = 1, n do
  b[i] = io.read("*n")
end
local alltask = {}
local tot = 1
local stagetask = {}

local function heldkarp_prepare()
  for i = 1, n do
    tot = tot * 2
    alltask[i] = {}
    stagetask[i] = {}
  end
  for i = 1, n do
    for j = 1, tot - 1 do
      -- set inf value
      alltask[i][j] = 1000000007
    end
  end
  for i = 1, tot - 1 do
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        ti = ti - 1
      end
      ti = ti / 2
    end
    table.insert(stagetask[cnt], i)
  end
  -- set first state
  local tmp = 1
  for i = 1, n do
    alltask[i][tmp] = i - 1
    tmp = tmp * 2
  end
end

local function heldkarp_doall()
  for stage = 1, n - 1 do
    local stlen = #stagetask[stage]
    for i_stagetask = 1, stlen do
      local used = stagetask[stage][i_stagetask]
      local t_used = used
      for i = 1, n do
        if t_used % 2 == 1 then
          local curcost = alltask[i][used]
          local v = (i + stage) % 2 == 0 and a[i] or b[i]
          local mul = 1
          local tmp = used
          local remcnt = 0
          for j = 1, n do
            if tmp % 2 == 0 then
              remcnt = remcnt + 1
              local jlen = remcnt - 1
              local nxtv = (j + stage + 1) % 2 == 0 and a[j] or b[j]
              if v <= nxtv then
                alltask[j][used + mul] = mmi(alltask[j][used + mul], jlen + curcost)
              end
            else
              tmp = tmp - 1
            end
            tmp = tmp / 2
            mul = mul * 2
          end
          t_used = t_used - 1
        end
        t_used = t_used / 2
      end
    end
  end
end

local function heldkarp_getresult()
  local ret = 1000000007
  for i = 1, n do
    ret = mmi(ret, alltask[i][tot - 1])
  end
  return ret
end
heldkarp_prepare()
heldkarp_doall()
local ans = heldkarp_getresult()
print(ans == 1000000007 and -1 or ans)
