	import java.util.Scanner;
	import java.util.ArrayList;
	import java.util.*;
		
		import java.io.*;
		public class mohamedy23 {
		  public static void main(String[]arg) {
			  Scanner sc=new Scanner(System.in);
			  int x=sc.nextInt();
			  int y=sc.nextInt();
			  int a[]=new int[x];
			  int b[]=new int[y];
			  for(int i=0;i<x;i++)a[i]=sc.nextInt();
			  for(int i=0;i<y;i++)b[i]=sc.nextInt();
			  Arrays.sort(a);Arrays.sort(b);
			  if(a[0]==1||b[0]==1) {
				  System.out.print(1);
			  }else {
				  System.out.print(Math.min(a[0],b[0])*10+Math.max(a[0],b[0]));
			  }
			    
			  }  
	}
	  
