using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new Stack<int>();
            var b = new Stack<int>();
            var c = new Stack<int>();
            var a2 = new Stack<int>();
            var b2 = new Stack<int>();
            var c2 = new Stack<int>();
            setST(a, b, c, a2, b2, c2);
            if (check(a, b, c)) { Console.WriteLine(0); goto exit; }
            var ans = new List<int>();
            var peeks = getPeeks(a, b, c);
            var first = false;
                if (peeks[0] > peeks[1] )
                {
                first = true;
                b.Push(a.Pop()); ans.Add(getAns(a, b, c, m, "ab"));
            }
            if (peeks[1] > peeks[0])
            {
                if (first) { a2.Push(b2.Pop()); ans.Add(getAns(a2, b2, c2, m, "ba")); goto next; }
                else
                {
                    first = true;
                    a.Push(b.Pop());
                    ans.Add(getAns(a, b, c, m, "ba"));
                }
            }
            if (peeks[1] > peeks[2])
            {
                if (first) { c2.Push(b2.Pop()); ans.Add(getAns(a2, b2, c2, m, "bc")); goto next; }
                else
                {
                    first = true;
                    c.Push(b.Pop());
                    ans.Add(getAns(a, b, c, m, "bc"));
                }
            }
            if (peeks[2] > peeks[1])
            {
                b2.Push(c2.Pop());
                ans.Add(getAns(a2, b2, c2, m, "cb"));
            }
            next:;
            putAns(ans);
            exit:;
        }
    }
    static void putAns (List<int> a )
    {
        var a2 = a.OrderBy(x => x).ToArray();
        if (a2[0] == -1 && a2[1] == -1) { Console.WriteLine(-1); return; }
        if (a2[0] == -1) { Console.WriteLine(a2[1]); return; }
        Console.WriteLine(a2[0]);
    }
    static int[] getPeeks(Stack<int> a, Stack<int> b, Stack<int> c)
    {
        var res = new int[3];
        res[0] = getPeek(a);
        res[1] = getPeek(b);
        res[2] = getPeek(c);
        return res;
    }
    static int getAns(Stack<int> a, Stack<int> b, Stack<int> c, int m, string pre)
    {
        if (check(a, b, c)) return 1;
        var count = 1;
        while (true)
        {
            var peeks = getPeeks(a, b, c);
            if (peeks[0] > peeks[1] && pre != "ba") { b.Push(a.Pop()); pre = "ab"; }
            else if (peeks[1] > peeks[0] && pre != "ab") { a.Push(b.Pop()); pre = "ba"; }
            else if (peeks[1] > peeks[2] && pre != "cb") { c.Push(b.Pop()); pre = "bc"; }
            else { b.Push(c.Pop()); pre = "cb"; }
            count++;
            if (check(a, b, c) && count <= m) return count;
            if (count > m) return -1;
        }
    }
    static int getPeek(Stack<int> a) => a.Count() == 0 ? 0 : a.Peek();
    static bool check(Stack<int> a, Stack<int> b, Stack<int> c) => (a.Count() == 0 && b.Count() == 0) | (b.Count() == 0 && c.Count() == 0);
    static void setST(Stack<int> a, Stack<int> b, Stack<int> c, Stack<int> a2, Stack<int> b2, Stack<int> c2)
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var p = int.Parse(line[0]);
        for (int i = 0; i < p; i++)
        {
            var w = int.Parse(line[i + 1]);
            a.Push(w); a2.Push(w);
        }
        line = Console.ReadLine().Trim().Split(' ');
        p = int.Parse(line[0]);
        for (int i = 0; i < p; i++)
        {
            var w = int.Parse(line[i + 1]);
            b.Push(w); b2.Push(w);
        }
        line = Console.ReadLine().Trim().Split(' ');
        p = int.Parse(line[0]);
        for (int i = 0; i < p; i++)
        {
            var w = int.Parse(line[i + 1]);
            c.Push(w); c2.Push(w);
        }
    }
}





Measured memory_bytes: 22720