import Control.Monad (replicateM)

type Glass = Int
type MaxGlass = Int
type Trays = ([Glass],[Glass],[Glass])
type Goal = Int

main = do
    [maxGlass,limit] <- getLine >>= return . map read . words
    if maxGlass == 0 && limit == 0 then return () else do
        [t1,t2,t3] <- replicateM 3 (getLine >>= return . map read . tail . words)
        print $ solve maxGlass limit (t1,t2,t3)
        main

solve :: MaxGlass -> Int -> Trays -> Int
solve maxGlass limit ts = count `seq` if count <= limit then count else -1
    where
    count = min (stack maxGlass ts 1) (stack maxGlass ts 3)

stack :: MaxGlass -> Trays -> Goal ->  Int
stack maxGlass ts@(t1,t2,t3) goal = stack' goal 1
    where
    stack' goal glass
        | glass > maxGlass = 0
        | goal == 1 && glass `elem` t1 || goal == 3 && glass `elem` t3
            = stack' goal (glass+1)
        | goal == 1 && glass `elem` t2 || goal == 3 && glass `elem` t2
            = 1 + (stack' (otherside goal) (glass+1)) + (move (glass+1))
        | goal == 1 && glass `elem` t3 || goal == 3 && glass `elem` t1
            = 2 + (stack' goal (glass+1)) + 2 * (move (glass+1))

    otherside 1 = 3
    otherside 3 = 1

    move glass
        | maxGlass <  glass = 0
        | otherwise         = 2 + 3 * move (glass+1)