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)
if a[0] == b[0]:
    print a[0]
    exit(0)
elif len(a) == 1:
    print a[0]
    exit(0)
elif len(b) == 1:
    print b[0]
    exit(0)
else:
    if a[0]<b[0]:
        if a[0] in b:
            print a[0]
            exit(0)
        print str(a[0])+str(b[0])
    else:
        if b[0] in a:
            print b[0]
            exit(0)
        print str(b[0]) + str(a[0])