import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

// 2^18 == 2.62144 * 10^5

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Int](N+1)
  val B = new Array[Int](N+1)
  for (i <- 1 to N) {
    A(i) = in.next().toInt
  }
  for (i <- 1 to N) {
    B(i) = in.next().toInt
  }

  //
  // 解けないなら -1 を返す反転すう的には満たせる前提
  def calc(revs: Array[Boolean]): Int = {
    val _all = new Array[Int](N+1)
    val ar = new Array[(Int, String)](N+1) // (value, "odd" | "even")

    for (i <- 1 to N) {
      if (revs(i)) { // 反転する
        _all(i) = B(i)

        if(i % 2 == 0)
          ar(i) = (B(i), "odd")
        else
          ar(i) = (B(i), "even")
      }
      else {
        _all(i) = A(i)

        if(i % 2 == 0)
          ar(i) = (A(i), "even")
        else
          ar(i) = (A(i), "odd")
      }
    }

    val all = _all.sorted

    var res = 0
    breakable {
      for (k <- 1 to N) {
        val now = all(k)

        if (k % 2 == 0) {
          var flag = false
          breakable {
            for (i <- k to N) {
              val (value, oe) = ar(i)
              if (value == now && oe == "even") {
                // swap & count
                for (j <- (k to i-1).reverse) {
                  res += 1
                  val tmp = ar(j+1)
                  ar(j+1) = ar(j)
                  ar(j) = tmp
                }

                flag = true
                break
              }
            }
          }
          if (!flag) {
            res = -1
            break
          }
        }
        else {
          var flag = false
          breakable {
            for (i <- k to N) {
              val (value, oe) = ar(i)
              if (value == now && oe == "odd") {
                // swap & count
                for (j <- (k to i-1).reverse) {
                  res += 1
                  val tmp = ar(j+1)
                  ar(j+1) = ar(j)
                  ar(j) = tmp
                }

                flag = true
                break
              }
            }
          }
          if (!flag) {
            res = -1
            break
          }
        }
      }
    }

    res
  }

  var ans = -1

  for (_bit <- 0 until 1<<N) {
    // 立ってたら偶奇反転
    var bit = _bit

    val ar = A.clone

    val revs = new Array[Boolean](N+1)

    var revCnt = 0
    var ind = 1
    while (bit > 0) {
      if (bit % 2 == 1) {
        revCnt += 1
        revs(ind) = true
      }

      bit /= 2
      ind += 1
    }

    if (revCnt % 2 == 0) {
      val res = calc(revs)

      if (res != -1) {
        if (ans == -1)
          ans = res
        else
          ans = ans min res
      }
    }
  }


  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 123500