

import java.util.Scanner;

public class CF870A 
{
	public static void main(String[] args)
	{
		CF870A task = new CF870A();
		Problem solver = task.new Problem();
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[m];
		for(int i = 0; i < a.length; i++)
			a[i] = in.nextInt();
		for(int i = 0; i < b.length; i++)
			b[i] = in.nextInt();
		System.out.println(solver.solve(a, b));
	}
	
	public class Problem
	{
		public Problem()
		{
			
		}
		
		private int mini(int a,int b)
		{
			int ans = b;
			
			if(a < b)
				ans = a;
			else
				ans = b;
			
			return ans;
		}
		
		public int solve(int[] a,int[] b)
		{
			int ans = Integer.MAX_VALUE;
			
			int min1 = Integer.MAX_VALUE;
			int min2 = min1;
			
			for(int i = 0; i < a.length; i++)
				min1 = mini(min1, a[i]);
			for(int i = 0; i < b.length; i++)
				min2 = mini(min2,b[i]);
		
			if(min1 != min2)
			{
				ans = mini(ans, ((min1 * 10) + min2));
				ans = mini(ans, ((min2 * 10) + min1));
				for(int i = 0; i < a.length; i++)
				{
					if(a[i] == min2)
					{
						ans = mini(ans,a[i]);
					}
				}
				for(int i = 0; i < b.length; i++)
				{
					if(b[i] == min1)
					{
						ans = mini(ans,b[i]);
					}
				}
			}
			else
			{
				ans = min1;
			}
			
			return ans;
		}
	}
}
