n,m = map(int,raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
a = sorted(a)
b = sorted(b)
pot = 0
if a[0] == b[0]:
    print a[0]
    exit(0)
elif len(b) == 1 and len(a) == 1:
    if a[0]<b[0]:
        print str(a[0]) + str(b[0])
    else:
        print str(b[0]) + str(a[0])
elif len(b) == 1 and b[0] in a:
    print b[0]
elif len(a) == 1 and a[0] in b:
    print a[0]
else:
    for zz in a:
        if zz not in b:
            pot = zz
            break
    for zz in b:
        if zz not in a and zz< pot:
            print zz
            exit(0)
    if pot != 0:
        print pot
        exit(0)
    if a[0]<b[0]:
        if a[0] in b:
            print a[0]
            exit(0)
        else:
            print str(a[0])+str(b[0])
    else:
        if b[0] in a:
            print b[0]
            exit(0)
        else:
            print str(b[0]) + str(a[0])