import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;

public class Main {

    public void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int a = 100;
        TreeSet<Integer> f = new TreeSet<>();
        TreeSet<Integer> s = new TreeSet<>();
        for(int i = 0; i < n; i++){
            f.add(nextInt());
        }
        int b = 10;
        for(int i = 0; i < m;i++){
            s.add(nextInt());
        }
        boolean t = true;
        for(int i = 1; i < 10; i++){
            for(int j = 1; j < 10; j++){
                if(t){
                    if(f.contains(i) && s.contains(j)){
                        t = false;
                        out.print(i +  "" + j);
                    }
                }
            }
        }
    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    public boolean hasNext() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }

    public Integer nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public Long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public Double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static void main(String[] args) throws IOException {
        try {
            Locale.setDefault(Locale.US);
        } catch (Exception e) {
        }
        new Main().run();
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("dragons.in"));
//            out = new PrintWriter(new File("dragons.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}