#include <iostream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
#define F first
#define S second
const int INF=100000000;

/*
int ans;
unsigned int n,m;

struct state{
	stack<int> s[3];
	int count,from,to;
};

void bfs(stack<int> si[3],int f,int t){
	state hoge;
	for(int i=0 ;i<3; ++i) hoge.s[i]=si[i];
	hoge.count=0;
	hoge.from=f;
	hoge.to=t;
	queue<state> que;
	que.push(hoge);
	while(!que.empty()){
		state st=que.front();
		que.pop();
		//cout << st.count << endl;
		//if(st.count>m) continue;
		if(st.s[0].size()==n||st.s[2].size()==n){
			ans=min(ans,st.count);
			return;
		}
		if(!(st.from==1&&st.to==0)&&st.s[0].size()!=0&&(st.s[1].size()==0||st.s[0].top()>st.s[1].top())){
			state ns=st;
			ns.s[1].push(ns.s[0].top());
			ns.s[0].pop();
			++ns.count;
			ns.from=0;
			ns.to=1;
			que.push(ns);
		}
		if(!(st.from==0&&st.to==1)&&st.s[1].size()!=0&&(st.s[0].size()==0||st.s[1].top()>st.s[0].top())){
			state ns=st;
			ns.s[0].push(ns.s[1].top());
			ns.s[1].pop();
			++ns.count;
			ns.from=1;
			ns.to=0;
			que.push(ns);
		} else if(!(st.from==2&&st.to==1)&&st.s[1].size()!=0&&(st.s[2].size()==0||st.s[1].top()>st.s[2].top())){
			state ns=st;
			ns.s[2].push(ns.s[1].top());
			ns.s[1].pop();//
			++ns.count;
			ns.from=1;
			ns.to=2;
			que.push(ns);
		}
		if(!(st.from==1&&st.to==2)&&st.s[2].size()!=0&&(st.s[1].size()==0||st.s[2].top()>st.s[1].top())){
			state ns=st;
			ns.s[1].push(ns.s[2].top());
			ns.s[2].pop();
			++ns.count;
			ns.from=2;
			ns.to=1;
			que.push(ns);
		}
	}
}

int pow(int a,int b){
	int res=1;
	for(int i=0; i<b; ++i){
		res*=a;
	}
	return res;
}

int main(){
	int pow3[16];
	for(int i=1; i<=15; ++i){
		pow3[i]=pow(3,i)-1;
	}
	while(cin >> n >> m){
	if(n==0&&m==0) break;
		ans=INF;
		stack<int> cup[3];
		for(int i=0; i<3; ++i){
			int q;
			cin >> q;
			for(int j=0; j<q; ++j){
				int tmp;
				cin >> tmp;
				cup[i].push(tmp);
			}
		}
		bfs(cup,0,1);
		if(ans!=INF)bfs(cup,1,0);
		if(ans!=INF)bfs(cup,1,2);
		if(ans!=INF)bfs(cup,2,1);
		if(ans!=INF)ans=min(ans,pow3[n]-ans);
		if(ans!=INF) cout << ans << endl;
		else cout << -1 << endl;
	}
	return 0;
}
*/

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		vector<vector<int> > goal(3);
		for(int i=0; i<3; ++i){
			int q;
			cin >> q;
			for(int j=0; j<q; ++j){
					int tmp;
					cin >> tmp;
					goal[i].push_back(tmp-1);
			}
		}

		vector<vector<int> > field(3);
		for(int i=0; i<n; ++i) field[0].push_back(i);
		
		int turn=0;
		int prev_from=-1;
		int prev_to=-1;
		while(true){
			if(field==goal) break;
			++turn;
			for(int from=0; from<3; ++from){
				if(field[from].size()==0) continue;
				const int cup=field[from].back();
				const int to_1=from-1;
				const int to_2=from+1;
				if(!(from==prev_to&&to_1==prev_from)&&to_1>=0&&(field[to_1].size()==0||field[to_1].back()<cup)){
					field[to_1].push_back(cup);
					field[from].pop_back();
					prev_from=from;
					prev_to=to_1;
					break;
				} else if(!(from==prev_to&&to_2==prev_from)&&to_2<3&&(field[to_2].size()==0||field[to_2].back()<cup)){
					field[to_2].push_back(cup);
					field[from].pop_back();
					prev_from=from;
					prev_to=to_2;
					break;
				}
			}
		}
		int MAXTURN=1;
		for(int i=0; i<n; ++i) MAXTURN*=3;
		--MAXTURN;
		turn=min(turn,MAXTURN-turn);
		if(turn>m) cout << -1 << endl;
		else cout << turn << endl;
	}
	return 0;
}

Measured memory_bytes: 1220