a,b = map(int,input().split())
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
for i in range(1,10):
    if i in aa and i in bb :
        print(i)
        exit(0)
for i in range(10,100):
    if ((i//10 in aa) and (i%10 in bb)) or ((i%10 in aa) and (i//10 in bb)):
        print(i)
        exit(0)
