n, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = float('inf')
for a in aa:
    for b in bb:
        if a == b:
            res = a
        else:
            res = min(a * 10 + b, b * 10 + a)
        ans = min(ans, res)
print(ans)
