sizes = input()

flag = False

in1 = input().split(' ')
in1 = sorted(list(map(int, in1)))

in2 = input().split(' ')
in2 = sorted(list(map(int, in2)))

for i in in1:
  if i in in2:
    print(i)
    flag = True
    break


if (flag == False):
  if(in1[0] < in2[0]):
    print(str(in1[0]) + str(in2[0]))
  else:
    print(str(in2[0]) + str(in1[0]))
	  	    		 		  				   		  		