n, m = map(int, input().split())
arr = set(map(int, input().split()))
arr1 = set(map(int, input().split()))
#print(arr, arr1)
for i in range(1, 100):
    j = str(i)
    if len(j) == 1 and i in arr and i in arr1:
        print(i)
        break
    if len(j) == 1:
        continue

    f = int(j[0]) in arr or int(j[1]) in arr
    f1 = int(j[0]) in arr1 or int(j[1]) in arr1
    #print(i, f, f1)
    if f and f1:
        print(i)
        break