import os
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if n >= 1 and n <= 9 and m >= 1 and m <= 9:
    if len(a) != n or len(b) != m:
        os.abort()
    min1 = 10
    min2 = 10
    for i in range(n):
        if a[i] >= 1 and a[i] <= 9:
            if a[i] < min1:
                min1 = a[i]
        else:
            os.abort()
    for j in range(m):
        if b[j] >= 1 and b[j] <= 9:
            if b[j] < min2:
                min2 = b[j]
        else:
            os.abort()
    if min1 == min2:
        c = min1
    else:
        if min1 > min2:
            c = min2 * 10 + min1
        else:
            c = min1 * 10 + min2    
    print(c) 
       