var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var [n,m]=arr.shift().split(" ").map(Number);
   if(n==0 && m==0)break;
   var [a,b,c]=arr.slice(0,3).map(v=>v.split(" ").slice(1).map(Number).reverse());
   var obj={};
   var result =-1;
   var bfs=[[a,b,c,0]];
   while(true){
      if(bfs.length==0)break;
      var [a,b,c,cnt]=bfs.shift();    
      if(cnt>m)break;
      if((a.length==0 && b.length==0) || (b.length==0 && c.length==0)){
         result=cnt;
         break;
       }
      var str="a"+a.join(",")+"b"+b.join(",")+"c"+c.join(",");
      if(obj.hasOwnProperty(str))continue;
      else obj[str]=1;    
      if(a.length==0)bfs.push([[b[0]],b.slice(1),c,cnt+1]);
      else if(b.length==0)bfs.push([a.slice(1),[a[0]],c,cnt+1]);
      else if(a[0]<b[0])bfs.push([[b[0]].concat(a),b.slice(1),c,cnt+1]);
      else if(a[0]>b[0])bfs.push([a.slice(1),[a[0]].concat(b),c,cnt+1]);
         
      if(b.length==0)bfs.push([a,[c[0]],c.slice(1),cnt+1]);
      else if(c.length==0)bfs.push([a,b.slice(1),[b[0]],cnt+1]);
      else if(b[0]<c[0])bfs.push([a,[c[0]].concat(b),c.slice(1),cnt+1]);
      else if(b[0]>c[0])bfs.push([a,b.slice(1),[b[0]].concat(c),cnt+1]);
   }
   console.log(result);
   arr=arr.slice(3);
}
