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();
        List<Integer> a = new ArrayList<>(n);
        List<Integer> b = new ArrayList<>(m);
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            b.add(sc.nextInt());
        }
        Collections.sort(a);
        Collections.sort(b);
        int minA = a.get(0);
        int minB = b.get(0);
        if(minA == minB){
            System.out.print(minB);
            return;
        }
        if(minA<minB){
            if(b.contains(minA)){
                System.out.print(minA);
                return;
            }
            if(a.contains(minB)){
                System.out.print(minB);
                return;
            }
            System.out.print(10*minA+minB);
        }
        if(a.contains(minB)){
            System.out.print(minB);
            return;
        }
        if(b.contains(minA)){
            System.out.print(minA);
            return;
        }
        System.out.print(10*minB+minA);
    }

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


    }

    /*static int doSmth(){

    }*/
}
