def main_function():
    n, k = [int(i) for i in input().split(" ")]
    a = sorted([int(i) for i in input().split(" ")])
    b = sorted([int(i) for i in input().split(" ")])
    d = {}
    for i in a + b:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    for i in d:
        if d[i] > 1:
            return i
    if a[0] < b[0]:
        return int(str(a[0]) + str(b[0]))
    return int(str(b[0]) + str(a[0]))





print(main_function())