from operator import itemgetter
#int(input())
#map(int,input().split())
#[list(map(int,input().split())) for i in range(q)]
#print("YES" * ans + "NO" * (1-ans))
n,m = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
ai2 = [0] * 10
for i in range(n):
    ai2[ai[i]] += 1
for i in range(m):
    ai2[bi[i]] += 1
ai.sort()
bi.sort()

ans = 100
for i in range(10):
    if ai2[i] == 2:
        ans = i
        break
print(min(ans,min(ai[0] * 10 + bi[0],bi[0] * 10 + ai[0])))
