/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int[] nArray = new int[n];
		int[] mArray = new int[m];
		
		for (int i = 0; i < n; i++){
			nArray[i] = scanner.nextInt();
			//System.out.println(i + " --> " + nArray[i]);
		}
		
		for (int i = 0; i < m; i++){
			mArray[i] = scanner.nextInt();
			//System.out.println(i + " --> " + mArray[i]);
		}
		
		
		Arrays.sort(nArray);
		Arrays.sort(mArray);
		
		int nNum = nArray[0];
		int mNum = mArray[0];
		
		
		/*
		for (int i = 0; i < n; i++){
			System.out.println(i + " --> " + nArray[i]);
		}
		System.out.println();
		for (int i = 0; i < n; i++){
		System.out.println(i + " --> " + mArray[i]);
		}
		*/
		
		
		if (nArray[0] == mArray[0]){
			System.out.print(mArray[0]);
		}
		else if (mArray[0] < nArray[0]){
			System.out.print(mArray[0]);
			System.out.print(nArray[0]);
		}
		else{
			System.out.print(nArray[0]);
			System.out.print(mArray[0]);
		}
		
	}
}