n, m = map(int, input().split())
N = set(map(int, input().split()))
M = set(map(int, input().split()))
mn = min(N)
mm = min(M)
N.intersection_update(M)
if len(N) == 0:
    if mn < mm:
        print(str(mn) + str(mm))
    elif mm < mn:
        print(str(mm) + str(mn))
else:
    print(min(N))
