n,m = map(int,raw_input().split())
nn = map(int,raw_input().split())
mm = map(int,raw_input().split())
nn = sorted(nn)
mm = sorted(mm)
if nn[0]==mm[0]:
    print nn[0]
else:
    x = min(nn[0],mm[0])
    y = max(nn[0],mm[0])
    z = x*10+y
    print z
