import java.util.*;
public class Main{
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        List<Integer>ls=new ArrayList<>();
        List<Integer>sl=new ArrayList<>();
      
        int n=sc.nextInt();
        int m=sc.nextInt();
        if(n<0 ||m<0)
        {
            System.out.println("Invalid input");
            return;
        }
        for(int i=0;i<n;i++)
        {
            ls.add(sc.nextInt());
        }
        for(int j=0;j<m;j++)
        {
            sl.add(sc.nextInt());
        }
        Set<Integer>union=new LinkedHashSet<>(ls);
        union.addAll(sl);
        if(union.isEmpty()) System.out.print("-1");
        else for(int x: union) System.out.print(x+" ");
        System.out.println();
        Set<Integer>intersection=new LinkedHashSet<>(ls);
        
        intersection.retainAll(sl);
        if(intersection.isEmpty()) System.out.print("-1");
        else for(int x: intersection) System.out.print(x+" ");
        System.out.println();
        
       
        Set<Integer>Difference=new LinkedHashSet<>(ls);
        Difference.removeAll(sl);
        if(difference.isEmpty()) System.out.print("-1");
        else for(int x:difference) System.out.print(x+" ");
       
        System.out.println();
         
        
        
    }
}