import java.util.*;
import java.util.Arrays;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //inputting two integers denoting two lines total number of elements
    int n = sc.nextInt();
    int m = sc.nextInt();

    //inputting the numbers(two lines) in two arrays 
    int [] na = new int[n];
    int [] ma = new int[m];

    //Initially taking minimum as 10 as the range is from 1 to 9, there is no of 10 to remain minimum in any case 
    /*int nmin = 10;
    int mmin = 10;*/

    //inputting the numbers of 1st line and cheking the lowest value at the same time
    
    for(int i = 0; i < na.length; ++i){
      na[i] = sc.nextInt();
      /*if(na[i] < nmin){
        nmin = na[i];
      }*/
    }
    Arrays.sort(na);

    //inputting the numbers of 2nd line and cheking the lowest value at the same time
    
    for(int j = 0; j < ma.length; ++j){
      ma[j] = sc.nextInt();
      /*if(ma[j] < mmin){
        mmin = ma[j];
      }*/
    }
    Arrays.sort(ma);

    //if in both case, the same value is minimum, we printing that number.
    if(na[0] == ma[0]){
      System.out.println(na[0]);
    } else { //else we are checking the minimum number of which line is smaller! then printing a number taking the smaller of the minimum numbers first, and then the bigger one! 
      if(na[0]<ma[0]){
        System.out.println(na[0]+""+ma[0]);
      }else{
        System.out.println(ma[0]+""+na[0]);
      }
    }
  }
}