#include <stdio.h>


int n,m;
int i,j,k,l;
int a,b,c,d[3],e,p,a2,b2,q,c2;
int A[16] = {-1} ,B[16] = {-1},C[16] = {-1};
int max = -1;
int A2[16] , B2[16],C2[16];
int count;
int ifa = -1,ifc= -1;
void input() {

  //  printf("strat input();\n");

  for(i=0;i<16;i++) {
    A[i] = -1;
    B[i] = -1;
    C[i] = -1;
    A2[i] = -1;
    B2[i] = -1;
    C2[i] = -1;
  }
    
    
  scanf("%d %d",&n,&m);
  // printf("n = %d\nm = %d\n",n,m);

  
  for(i = 0;i<3; i++) {

    scanf("%d",&d[i]);
    // printf("d[%d] = %d\n",i,d[i]);
    k = 1;

    for(j=0; j<d[i]; j++) {
      scanf("%d",&e);

      if(i == 0) {
	A[k] = e;
	A2[k] = e;
	//	printf("A[%d] = %d\n",k,A[k]);
      } else if(i ==1) {
	B[k] = e;
	B2[k] = e;
	//	printf("B[%d] = %d\n",k,B[k]);
      } else if(i ==2){
	C[k] = e;
	C2[k] = e;
	//	printf("C[%d] = %d\n",k,C[k]);
      }

      k++;
    }
  }

  a = d[0];
  b = d[1];
  c = d[2];

  k = 0;
}

void BtoA() {
  a++;	
  // printf("B[%d](%d) => A[%d](%d)\n",b,B[b],a,A[a]);
  A[a] = B[b];
  B[b] = -1;
  b--;
  k++;

}  

void CtoB() {
  b++;
  // printf("C[%d](%d) => B[%d](%d)\n",c,C[c],b,B[b]);
  B[b] = C[c];
  C[c] = -1;
  c--;
  k++;
}

void BtoC() {
  c++;
  // printf("B[%d](%d) => C[%d](%d)\n",b,B[b],c,C[c]);
  C[c] = B[b];
  B[b] = -1;
  b--;
  k++;
	
}

void AtoB() {
  b++;
  // printf("A[%d](%d) => B[%d](%d)\n",a,A[a],b,B[b]);
  B[b] = A[a];
  A[a] = -1;
  a--;
  k++;
}

void CtoA() {
  a++;
  // printf("C[%d](%d) => A[%d](%d)\n",c,C[c],a,A[a]);
  A[a] = C[c];
  C[c] = -1;
  c--;
  k += 2;
}

void AtoC() {
  c++;
  // printf("A[%d](%d) => C[%d](%d)\n",a,A[a],c,C[c]);
  C[c] = A[a];
  A[a] = -1;
  a--;
  k += 2;
}

void IFC() {
  ifc = -1;
  //  printf("start IFC();\n");

  e = 0;
  while(1) {

    if(c == 0 && b == 0){
      ifc = 0;
      break;
    }else if(k+q >=m){
      ifc = 0;
      break;
    } else if(a == 0 && b == 0) {
      ifc = 0;
      break;
    }

    if(C[c] < B[b] && e != 2 ) {
      BtoC();
      e = 1;
    } else if(B[b] < C[c] && e != 1){
      CtoB();
      e = 2;
    } else if(A[a] < B[b] && e != 4) {
      BtoA();
      e = 3;
    } else if(B[b] < A[a] && e !=3) {
      AtoB();
      e = 4;
    } else break;


  }
}
    
    

void IFA() {

  //  printf("Start IFA();\n");
  e = 0;
  ifa = -1;
while(1) {

  // printf("{A[%d]=%d} {B[%d]=%d} {C[%d]=%d}\n",a,A[a],b,B[b],c,C[c]);

  if(c == 0 && b == 0 ) {
    ifa = 0;
    break;
  } else if(k+q >= m) {
    ifa = 0;
    break;
  }else if(a == 0 && b == 0) {
    ifa = 0;
    break;
  }
  
  
  if(A[a] < B[b] && e !=2 ) {
    BtoA();
    e = 1;
  } else if(B[b] < A[a] && e !=1 && A[a] != a) {
      AtoB();
      e = 2;
  }else if(C[c] < B[b] && e !=4) {
    BtoC();
    e = 3;
  } else if(B[b] < C[c] && e !=3) {
    CtoB();
    e = 4;
  } else {
    break;
  }

  //  printf("c = %d\n",e);
 }
 
}
  
  




int main() {
  
  while(1) {

    input(); 

    if(n == 0 && m == 0) break;
  
    q = 0;   
    k = 0;
    IFA();
    // printf("Finish IFA(); k = %d\n",k);
    a2 = a;
    b2 = b;
    c2 = c;
    p = k;
    k = 0;
    q = 0;
    for(i = 0;i<16;i++) {
      A[i] = A2[i];
      B[i] = B2[i];
      C[i] = C2[i];
    }
    a = d[0];
    b = d[1];
    c = d[2];
    
    IFC();
    // printf("Finish IFC(); k = %d\n",k);    
    
    if(ifc == 0 && ifa == 0) {
      if(p < k) k = p;

        printf("%d\n",k);
    } else if(ifc == 0) printf("%d\n",k);
    else if(ifa == 0) printf("%d\n",p);
    else printf("-1\n");
    
  }

  return 0;
}

Measured memory_bytes: 600