def common_elements(n1, n2):
    common = list()
    for i in n1:
        if i in n2:
            common.append(i)
    if len(common):
        return common
    else:
        return 0


def main():
    ans = 0
    ls = list(map(int, input().split(" ")))
    n1 = list(map(int, input().split(" ")))
    n2 = list(map(int, input().split(" ")))
    common = common_elements(n1, n2)
    if common:
        ans = min(common)
    else:
        d1 = min(n1)
        d2 = min(n2)
        ans = (min(d1, d2) * 10) + max(d1, d2)
    print(ans)

main()
        
