input()
a = [int(k) for k in input().split(' ') if k]
b = [int(k) for k in input().split(' ') if k]
a.sort()
b.sort()
result = sorted([a[0], b[0]])
if result[0] == result[1]:
    print(result[0])
else:
    print(*result, sep='')
