#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

bool searched[15000000];

int main() {
    int N, M;
    vector<int> ans;
    int num;
    int tmp;
    int state1, state2, state3;
    pair<int, int> state;
    int S;
    int tmpans;
    while(true){
        cin>>N>>M;
        if((N==0) && (M==0)) break;
        for(int i=0;i<pow(3, N);++i){
            searched[i] = false;
        }
        S = 0;
        cin>>num;
        for(int i=0;i<num;++i){
            cin>>tmp;
        }
        cin>>num;
        for(int i=0;i<num;++i){
            cin>>tmp;
            S += int(pow(3, tmp-1));
        }
        cin>>num;
        for(int i=0;i<num;++i){
            cin>>tmp;
            S += 2*int(pow(3, tmp-1));
        }
        queue<pair<int, int> > que;
        que.push(mp(S, 0));
        searched[S] = true;
        while(!que.empty()){
            state = que.front();que.pop();
            S = state.fi;
            tmpans = state.se;
            state1 = -1;
            state2 = -1;
            state3 = -1;
            for(int i=N-1;i>=0;--i){
                if((state1!=-1) && (state2!=-1) && (state3!=-1)) break;
                if(S/int(pow(3, i))==0){
                    if(state1==-1) state1 = i;
                    S %= int(pow(3, i));
                }
                else if(S/int(pow(3, i))==1){
                    if(state2==-1) state2 = i;
                    S %= int(pow(3, i));
                }
                else {
                    if(state3==-1) state3 = i;
                    S %= int(pow(3, i));
                }
            }
            S = state.fi;
            if(((state1==-1)&&(state2==-1)) || ((state2==-1)&&(state3==-1))){
                ans.push_back(tmpans);
                break;
            }
            if(tmpans>M){
                ans.push_back(-1);
                break;
            }
            // 1 -> 2
            if((state1!=-1) && ((state2==-1) || (state1>state2))){
                S += int(pow(3, state1));
                if(!searched[S]){
                    searched[S] = true;
                    que.push(mp(S,tmpans+1));
                }
                S -= int(pow(3, state1));
            }
            // 2 -> 1
            if((state2!=-1) && ((state1==-1) || (state2>state1))){
                S -= int(pow(3, state2));
                if(!searched[S]){
                    searched[S] = true;
                    que.push(mp(S,tmpans+1));
                }
                S += int(pow(3, state2));
            }
            // 2 -> 3
            if((state2!=-1) && ((state3==-1) || (state2>state3))){
                S += int(pow(3, state2));
                if(!searched[S]){
                    searched[S] = true;
                    que.push(mp(S,tmpans+1));
                }
                S -= int(pow(3, state2));
            }
            // 3 -> 2
            if((state3!=-1) && ((state2==-1) || (state3>state2))){
                S -= int(pow(3, state3));
                if(!searched[S]){
                    searched[S] = true;
                    que.push(mp(S,tmpans+1));
                }
                S += int(pow(3, state3));
            }
        }
    }
    for(int i=0;i<ans.size();++i){
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 17248