def solve(n, m, a, b):
    xa = set(a)
    xb = set(b)
    iab = xa & xb
    if iab:
        return min(iab)
    else:
        minxa = min(xa)
        minxb = min(xb)
        return str(min(minxa, minxb)) + str(max(minxa, minxb))
    


def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print(solve(n, m, a, b))


main()
