#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
bool memo[3][3][3][3][3][3][3][3][3][3][3][3][3][3][3]={};
vector<vector<int> >cup3(10);
bool check(int num,int point){
  int hi[15]={};

   for(int i=0;i<3;i++)
    for(int j=0;j<cup3[i].size();j++)
      {hi[cup3[i][j]]=i;}
  hi[num]=point;

  //cout<<memo[hi[0]][hi[1]][hi[2]][hi[3]][hi[4]][hi[5]][hi[6]][hi[7]][hi[8]][hi[9]][hi[10]][hi[11]][hi[12]][hi[13]][hi[14]]<<endl;

  if(!(memo[hi[0]][hi[1]][hi[2]][hi[3]][hi[4]][hi[5]][hi[6]][hi[7]][hi[8]][hi[9]][hi[10]][hi[11]][hi[12]][hi[13]][hi[14]])&&cup3[point].size()==0){
    return true;
  }else if(!(memo[hi[0]][hi[1]][hi[2]][hi[3]][hi[4]][hi[5]][hi[6]][hi[7]][hi[8]][hi[9]][hi[10]][hi[11]][hi[12]][hi[13]][hi[14]])&&(num>cup3[point][cup3[point].size()-1])){
    return true;
  }else{
    return false;
  }
}
void renew(){
  int hai[15]={};
  for(int i=0;i<3;i++)
    for(int j=0;j<cup3[i].size();j++)
      hai[cup3[i][j]]=i;
  memo[hai[0]][hai[1]][hai[2]][hai[3]][hai[4]][hai[5]][hai[6]][hai[7]][hai[8]][hai[9]][hai[10]][hai[11]][hai[12]][hai[13]][hai[14]]=true;
}
int main(){
  int n,m;while(cin>>n>>m,n+m){
    cup3[0].clear();cup3[1].clear();
    cup3[2].clear();
    memset(memo,0,sizeof(memo));
  for(int i=0;i<3;i++){
    int a;cin>>a;
    for(int j=0;j<a;j++){
      int b;cin>>b;
      b--;
      cup3[i].pb(b);
    }
  }

  renew();
 
  bool flagg=true;
  queue<pair<pair<int,int>,pair<vector<vector<int> >,int> > >que;
  vector<vector<int> >cup2(3);

  for(int i=0;i<3;i++){
 
    for(int j=0;j<cup3[i].size();j++){
      // cout<<cup3[i][j]<<" ";
      cup2[i].pb(cup3[i][j]);
    }
    //cout<<endl;
  }
  for(int i=0;i<3;i++)
    if(cup3[i].size()!=0){
      que.push(mp(mp(cup3[i][cup3[i].size()-1],0),mp(cup2,i)));
      //cout<<i<<endl;
    }
  while(!que.empty()){
 
    cup3[0].clear();cup3[1].clear();cup3[2].clear();
    for(int i=0;i<3;i++){
      for(int j=0;j<que.front().S.F[i].size();j++){
	//cout<<que.front().S.F[i][j]<<" ";
	cup3[i].pb(que.front().S.F[i][j]);
      }
      //cout<<endl;
    }

    int point=que.front().S.S;
    int num=que.front().F.F;
    int cnt=que.front().F.S;
    que.pop();
    //cout<<point;
    //cout<<"-----------------------"<<endl;
    /*for(int i=0;i<3;i++){
	for(int j=0;j<cup3[i].size();j++)
	  cout<<cup3[i][j]<<" ";
	cout<<endl;
	}*/
      //cout<<"-----------------------"<<endl;
    if(cup3[0].size()==n||cup3[2].size()==n){

      cout<<cnt<<endl;
      flagg=false;
      break;
    }
    if(cnt>=m)break;
    if(point==0){
      if(check(num,1)){
	cup3[point].pop_back();
	cup3[1].pb(num);
	renew();
	for(int i=0;i<3;i++){
	  if(cup3[i].size()!=0)
	  que.push(mp(mp(cup3[i][cup3[i].size()-1],cnt+1),mp(cup3,i)));
	}
      }
    }else if(point==1){
      if(check(num,0)){

	cup3[point].pop_back();
	cup3[0].pb(num);
	renew();
	for(int i=0;i<3;i++){
	  if(cup3[i].size()!=0)
	    que.push(mp(mp(cup3[i][cup3[i].size()-1],cnt+1),mp(cup3,i)));
	}
	cup3[0].pop_back();
	cup3[point].pb(num);
      }
      if(check(num,2)){
	cup3[point].pop_back();
	cup3[2].pb(num);
	renew();
	for(int i=0;i<3;i++){
	  if(cup3[i].size()!=0)
	  que.push(mp(mp(cup3[i][cup3[i].size()-1],cnt+1),mp(cup3,i)));
	}
	cup3[2].pop_back();
	cup3[point].pb(num);
      }
    }else if(point == 2){
      if(check(num,1)){
	//cout<<point<<" "<<point<<endl;
	cup3[point].pop_back();
	cup3[1].pb(num);
	renew();
	for(int i=0;i<3;i++){
	  if(cup3[i].size()!=0){
	    // cout<<point<<endl;
	  que.push(mp(mp(cup3[i][cup3[i].size()-1],cnt+1),mp(cup3,i)));
	  }
	}
      }
    }
  }
  if(flagg)
    cout<<-1<<endl;
  }
  return 0;
}



Measured memory_bytes: 17028