import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();
        int[] mass = new int[a];
        int[] bbb = new int[b];
        for (int i = 0; i < a; i++){
            int x = in.nextInt();
            mass[i] = x;
        }
        for (int i = 0; i < b; i++){
            int o = in.nextInt();
            bbb[i] = o;
        }
        int min = mass[0];
        int min1 = bbb[0];
        for (int i = 0; i < mass.length; i++){
            if (mass[i] <= min){
                min = mass[i];
            }
        }
        for (int i = 0; i < bbb.length; i++){
            if (bbb[i] <= min1){
                min1 = bbb[i];
            }
        }
        if (min == min1){
            System.out.println(min);
        }
        else if(min < min1){
            int y = min * 10 + min1;
            System.out.println(y);
        }
        else{
            int u = min1 * 10 + min;
            System.out.println(u);
        }




    }



    void run() {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out)) {


            solve(in, out);


        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}
