import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        int[] a = new int[N];
        int[] b = new int[M];
        for (int i = 0; i < N; i++) {
            a[i]=in.nextInt();
        }
        for (int i = 0; i < M; i++) {
            b[i]=in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        if(a[0]==b[0]){
            System.out.print(a[0]);
        }
        else if(a[0]>b[0]){
            System.out.print(a[0]+10*b[0]);
        }
        else{
            System.out.print(b[0]+10*a[0]);
        }

    }
}
