n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ok = True
for i in range(n):
    if a[i] in b:
        print(a[i])
        ok = False
        break
if ok:
    print(a[0], end = '')
    print(b[0])
