import java.lang.reflect.Array;
import java.util.*;

public class Main {

    static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int [n];
        int[] b = new int [m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        int minA = a[0];
        int minB = b[0];
        if(minA == minB){
            System.out.print(minB);
            return;
        }
        int val = minA<minB ? 10*minA+minB :10*minB+minA;
        System.out.print(val);
    }

    public static void main(String[] args) {
        solve();


    }

    /*static int doSmth(){

    }*/
}
