import javax.swing.plaf.IconUIResource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();
//        int t=sc.nextInt();
//        outer:while (t-->=1) {
            int n = sc.nextInt();
            int m=sc.nextInt();
            int a[]=sc.readArray(n);
            int b[]=sc.readArray(m);
            int min1=Integer.MAX_VALUE;
            int min2=Integer.MAX_VALUE;
            for (int i=0;i<n;i++){
                min1=Integer.min(min1,a[i]);

            }
            for (int i=0;i<m;i++){
                min2=Integer.min(min2,b[i]);

            }
            if (min1==min2){
                System.out.println(min1);
            }
            else System.out.println(Math.min(min1,min2)+""+Math.max(min1,min2));

        }


    static void sort(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }
    static void sortLong(long[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (long i : a) l.add((int)i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static void sortReverse(long[] a) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a) l.add(i);
        Collections.sort(l, Collections.reverseOrder());
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }


        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
        long[] readArrayLong(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}



