import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class F1 {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] str = br.readLine().split(" ");
			//int n = Integer.parseInt(str[0]);
			//int m = Integer.parseInt(str[1]);
			
			int min1 = 10;
			int min2 = 10;
			str = br.readLine().split(" ");
			for(String s: str) {
				int a = Integer.parseInt(s);
				if (a < min1) min1 = a;
			}
			
			str = br.readLine().split(" ");
			for(String s: str) {
				int a = Integer.parseInt(s);
				if(a < min2) min2 = a;
			}
				
			if(min1 == min2) {
				System.out.println(min1);
			}else if(min1 < min2) {
				System.out.println(min1 + "" + min2);
			}else if(min2 < min1) {
				System.out.println(min2 + "" + min1);
			}
			
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
