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]
else:
    if a<b:
        print str(a[0])+str(b[0])
    else:
        print str(b[0]) + str(a[0])