import java.lang.Integer
import java.lang.Math

fun main(args: Array<String>) {
  val INF = 1000000000
  val n = readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
  val b = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
  val m = 1 shl n
  val dp = Array(m) { IntArray(51) { INF } }
  dp[0][0] = 0
  for (k in 0 until m) {
    for (i in 1..50) dp[k][i] = Math.min(dp[k][i],dp[k][i-1])
    val x = Integer.bitCount(k)
    for (i in 0 until n) {
      if (((k shr i) and 1) == 1) continue
      val v = if ((x-i)%2 == 0) a[i] else b[i]
      val j = k or (1 shl i)
      dp[j][v] = Math.min(dp[j][v], dp[k][v]+Integer.bitCount(k shr i))
    }
  }
  val x = dp[m-1].min()!!
  println(if (x == INF) -1 else x)
}