#n, k = map(int, input().split(" "))        # read multiple integers into different variables
#L = [int(x) for x in input().split()]      # read multiple integers into a list
#print(' '.join(map(str, L)))               # print multiple integers in one line

n, m = map(int, input().split(" "))  
a = [int(x) for x in input().split()]      # read multiple integers into a list
b = [int(x) for x in input().split()]      # read multiple integers into a list
a.sort()
b.sort()

if (a[0] == b[0]) : print(a[0])
elif (a[0] < b[0]) : print(a[0] * 10 + b[0])
else : print(b[0] * 10 + a[0])
