import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.Set (Set)
import qualified Data.Set as S

main :: IO ()
main = do
  [n, m] <- f
  unless (n == 0 && m == 0) $ do
    xs <- reverse <$> tail <$> f
    ys <- reverse <$> tail <$> f
    zs <- reverse <$> tail <$> f
    print $ solve n m (xs, ys, zs)
    main
  where f = map read <$> words <$> getLine
  
solve :: Int -> Int -> ([Int], [Int], [Int]) -> Int
solve n m cup = f (S.insert cup S.empty) (S.insert cup S.empty) 0
  where f hs cs ct | ct > m = (-1)
                   | S.member g1 cs || S.member g2 cs = ct
                   | otherwise = let ns = S.foldl h S.empty cs in f (S.union hs ns) (S.difference ns hs) (ct+1)
        h s ([], [], (z:zs)) = S.insert ([], [z], zs) s
        h s ((x:xs), [], []) = S.insert (xs, [x], []) s
        h s ([], (y:ys), []) = S.insert ([], ys, [y]) (S.insert ([y], ys, []) s)
        h s ([], (y:ys), (z:zs)) = let s' = S.insert ([y],ys,(z:zs)) s
                                   in S.insert (if y > z then ([], ys, (y:z:zs)) else ([], (z:y:ys), zs)) s'
        h s ((x:xs), [], (z:zs)) = let s' = S.insert (xs, [x], (z:zs)) s
                                   in S.insert ((x:xs), [z], zs) s'
        h s ((x:xs), (y:ys), []) = let s' = S.insert ((x:xs), ys, [y]) s
                                   in S.insert (if x > y then (xs, (x:y:ys), []) else ((y:x:xs), ys, [])) s'
        h s ((x:xs), (y:ys), (z:zs)) = let s' = S.insert (if x > y then (xs, (x:y:ys), (z:zs)) else ((y:x:xs), ys, (z:zs))) s
                                       in S.insert (if y > z then ((x:xs), ys, (y:z:zs)) else ((x:xs), (z:y:ys), zs)) s'
        g1 = ([n,n-1 .. 1], [], [])
        g2 = ([], [], [n,n-1 .. 1])

