import java.io.*;
import java.util.*;

public class Test1 {
    public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt(), m = in.nextInt(), a1[] = new int[n], a2[] = new int[m];
        for(int i = 0; i<n; i++) a1[i] = in.nextInt();
        for(int i = 0; i<m; i++) a2[i] = in.nextInt();
        Arrays.sort(a1);
        Arrays.sort(a2);
        Set<Integer> s = new TreeSet<>();
        s.add(a1[0]);
        s.add(a2[0]);
        s.forEach(p->System.out.print(p));
    }
}