


import java.util.Scanner;


public class water2 {
	public static Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		while(cin.hasNext()) {
			int n=cin.nextInt();
			int m=cin.nextInt();
			int minn=10;
			int minm=10;
			for(int i=0;i<n;i++) {
				int tmp=cin.nextInt();
				if(tmp<minn) {
					minn=tmp;
				}
			}
			for(int i=0;i<m;i++) {
				int tmp=cin.nextInt();
				if(tmp<minm) {
					minm=tmp;
				}
			}
			if(minn==minm) {
				System.out.println(minn);
			}else if(minn<minm){
				System.out.println(minn*10+minm);
			}else {
				System.out.println(minm*10+minn);
			}
		}
	}
}
