

import java.util.Scanner;




public class JavaApplication170 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);


        int n = sc.nextInt();
        int x = sc.nextInt();
        int smallest = Integer.MAX_VALUE;
        String xx = "";
        for(int i=0; i<n; i++){
            int k = sc.nextInt();
            if(smallest > k){
                smallest = k;
            }
        }
        xx += smallest;
        smallest = Integer.MAX_VALUE;
        for(int i=0; i<x; i++){
            int u = sc.nextInt();
            if(smallest > u)
                smallest = u;
        }
        xx += smallest;
        if(xx.charAt(0) == xx.charAt(1))
            System.out.println(xx.charAt(0));
        else
        System.out.println(xx);
        
    }
    
}
 
