import scala.collection.mutable
import util.control.Breaks._

object Main extends App {
  case class State(a: Int, b: Int, c: Int)
  val cache = mutable.HashMap.empty[Int, Int]
  val stateCache = mutable.HashMap.empty[State, Boolean]
  def head (b: Int, n: Int): Int = cache.getOrElseUpdate(b, {
    var h = 1 << n-1
    breakable {
      while (h > 0) {
        if ((h & b) == h) break()
        h = h >> 1
      }
    }
    h
  })
  def readLine: Array[Int] = io.StdIn.readLine().split(' ').map(_.toInt)
  def solver(n: Int, m: Int): Unit = {
    val Array(_, as @ _*) = readLine
    val Array(_, bs @ _*) = readLine
    val Array(_, cs @ _*) = readLine
    val queue = mutable.Queue.empty[(State, Int)]
    val state: Array[Int] = for (x <- Array(as,bs,cs)) yield x.foldLeft(0)((acc, i) => acc | (1 << i - 1))
    queue.enqueue((State(state(0), state(1), state(2)), 0))
    var count = -1
    val goal = (1 << n) - 1
    def enq(ns: State, nc: Int): Unit =
      if (!stateCache.getOrElseUpdate(ns, false)) {queue.enqueue((ns, nc)); stateCache += (ns -> true)}

    breakable {
      while (queue.nonEmpty) {
        val (s, c) = queue.dequeue()

        if (c > m) break()
        if (s.a == goal || s.c == goal) {count = c; break()}

        val (h0, h1, h2) = (head(s.a, n), head(s.b, n), head(s.c, n))

        if (h0 > h1) enq(State(s.a ^ h0, h0 | s.b, s.c),c+1)
        else if (h1 > h0) enq(State(h1 | s.a, s.b ^ h1, s.c), c+1)
        if (h1 > h2) enq(State(s.a, s.b ^ h1, h1 | s.c), c+1)
        else if (h2 > h1) enq(State(s.a, h2 | s.b, s.c ^ h2), c+1)
      }
    }
    println(count)
  }
  breakable(
    while(true) {
      val Array(n, m) = readLine
      if (n == 0 || m == 0) break()
      else solver(n, m)
    }
  )
}
