a=[]
b=[]
n,m=map(int,input().split())
a=input().split()
for i in range(n):
    a[i]=int(a[i])
k=min(a)
b=input().split()
for i in range(m):
    b[i]=int(b[i])
d=min(b)
"""for i in range(n):
    if a[i]<k:
        k=a[i]
for i in range(m):
    if b[i]<d:
        d=b[i]"""
if d==k:
    print(d)
if d>k:
    print(10*k+d)
if k>d:
    print(10*d+k)
