import sys
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
for i in range (n):
    if a[i] in b :
        print(a[i])
        sys.exit(0)
print (min(a[0], b[0]) * 10 + max(a[0], b[0]))
