#include<iostream>
#include<queue>
#include<stack>
using namespace std;
struct QS{
    stack< int > D[3];
    int cnt;
    int prev;
    //A->B 1
    //A<-B 2
    //B->C 3
    //B<-C 4
};
int m,n;
queue< QS > Q;
int BFS(){
    while(!Q.empty()){
        if(Q.front().cnt>m)return -1;

        if(Q.front().D[0].size()==n)return Q.front().cnt;
        if(Q.front().D[2].size()==n)return Q.front().cnt;

        //cout<<"prev = "<<Q.front().prev<<endl;

        int x = Q.front().D[0].empty() ? 0 : Q.front().D[0].top();
        int y = Q.front().D[1].empty() ? 0 : Q.front().D[1].top();
        int z = Q.front().D[2].empty() ? 0 : Q.front().D[2].top();

        QS sub = Q.front();
        if(x > y&&sub.prev!=2){
            sub.D[1].push(sub.D[0].top());
            sub.D[0].pop();
            sub.cnt++;
            sub.prev = 1;
            Q.push(sub);

        }
        sub = Q.front();
        if(x < y&&sub.prev!=1){
            sub.D[0].push(sub.D[1].top());
            sub.D[1].pop();
            sub.cnt++;
            sub.prev = 2;
            Q.push(sub);
        }

        sub = Q.front();
        if(y > z&&sub.prev!=4){
            sub.D[2].push(sub.D[1].top());
            sub.D[1].pop();
            sub.cnt++;
            sub.prev = 3;
            Q.push(sub);
        }
        sub = Q.front();
        if(y < z&&sub.prev!=3){
            sub.D[1].push(sub.D[2].top());
            sub.D[2].pop();
            sub.cnt++;
            sub.prev = 4;
            Q.push(sub);
        }
        Q.pop();
    }
    return -1;
}
int main(){


    while(cin>>n>>m,n||m){
        while(!Q.empty())Q.pop();
        QS data;
        for(int i = 0;i < 3;i++){
            int x;
            cin>>x;
            for(int j = 0;j < x;j++){
                int y;
                cin>>y;
                data.D[i].push(y);
            }
        }
        data.cnt = 0;
        data.prev = -1;
        Q.push(data);
        cout<<BFS()<<endl;

    }

    return 0;
}