#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int limit,num_cup,ans;
bool Log[14348907],FLG;
char ch;
short a_loc,b_loc,c_loc;


struct Info{
	int value;
	char loc;
};

struct Data{
	Data(){
		count = 0;
	}
	Data(int arg_count,char arg_table[15]){
		count = arg_count;
		for(int i = 0; i < 15; i++)table[i] = arg_table[i];
	}
	char table[15];
	int count;
};

void setCode(char table[15], int &calc){
	int S = 1;
	calc = 0;
	for(int i = 0; i < num_cup; i++){
		if(table[i] == 'A'){
			calc += 0;
		}else if(table[i] == 'B'){
			calc += S;
		}else{
			calc += 2*S;
		}
		S *= 3;
	}
}

void bfs(char table[15]){

	queue<Data> Q;
 	Q.push(Data(0,table));
 	char new_table[4][15];

 	Data tmp;
 	while(!Q.empty()){
 		tmp.count = Q.front().count;
 		for(int i = 0; i < 15; i++){
 			tmp.table[i] = Q.front().table[i];
 		}
 		Q.pop();

 		FLG = true;
 		ch = tmp.table[0];

 		if(ch == 'B')FLG = false;

 		if(FLG){
 			for(int i = 1; i <= num_cup-1; i++){
 				if(tmp.table[i] != ch){
 					FLG = false;
 					break;
 				}
 			}
 		}

 		if(FLG){
 			ans = tmp.count;
 			break;
 		}

 		if(tmp.count == limit){
 			continue;
 		}

 		for(int i = 0; i < 4; i++){
 			for(int k = 0; k < num_cup; k++)new_table[i][k] = tmp.table[k];
 		}

 		a_loc = b_loc = c_loc = -1;
 		for(int i = num_cup-1; i >= 0; i--){
 			if(tmp.table[i] == 'A'){
 				a_loc = (a_loc >= i)?a_loc:i;
 			}else if(tmp.table[i] == 'B'){
 				b_loc = (b_loc >= i)?b_loc:i;
 			}else{
 				c_loc = (c_loc >= i)?c_loc:i;
 			}
 		}

 		int calc;

 		if(a_loc > b_loc){
 			new_table[0][a_loc] = 'B';

 			setCode(new_table[0],calc);
 			if(Log[calc] == false){
 				Log[calc] = true;
 				Q.push(Data(tmp.count+1,new_table[0]));
 			}
 		}

 		if(b_loc > a_loc){
 			new_table[1][b_loc] = 'A';

 			setCode(new_table[1],calc);
 			if(Log[calc] == false){
 				Log[calc] = true;
 				Q.push(Data(tmp.count+1,new_table[1]));
 			}
 		}

 		if(c_loc > b_loc){
 			new_table[2][c_loc] = 'B';

 			setCode(new_table[2],calc);
 			if(Log[calc] == false){
 				Log[calc] = true;
 				Q.push(Data(tmp.count+1,new_table[2]));
 			}
 		}

 		if(b_loc > c_loc){
 			new_table[3][b_loc] = 'C';

 			setCode(new_table[3],calc);
 			if(Log[calc] == false){
 				Log[calc] = true;
 				Q.push(Data(tmp.count+1,new_table[3]));
 			}
 		}
 	}
 }

int main(){

	int a,b,c,index,calc;
	Info info[15];
	char table[15];

	while(true){
		scanf("%d %d",&num_cup,&limit);
		if(num_cup == 0 && limit == 0)break;

		for(int i = 0; i < 14348907; i++){
			Log[i] = false;
		}

		index = 0;
		scanf("%d",&a);

		for(int i = 0; i < a; i++){
			scanf("%d",&info[index].value);
			info[index].loc = 'A';
			index++;
		}

		scanf("%d",&b);
		for(int i = 0; i < b; i++){
			scanf("%d",&info[index].value);
			info[index].loc = 'B';
			index++;
		}

		scanf("%d",&c);
		for(int i = 0; i < c; i++){
			scanf("%d",&info[index].value);
			info[index].loc = 'C';
			index++;
		}

		for(int i = 1; i <= num_cup-1; i++){
			for(int k = num_cup-1; k >= i; k--){
				if(info[k].value < info[k-1].value)swap(info[k],info[k-1]);
			}
		}

		for(int i = 0; i < num_cup;i++){
			table[i] = info[i].loc;
		}

		setCode(table,calc);

		Log[calc] = true;

		ans = -1;

		bfs(table);

		printf("%d\n",ans);

	}


	return 0;
}

Measured memory_bytes: 16588