n,m=map(int,input().split())
t = set(map(int,input().split()))
r = set(map(int,input().split()))
result = t&r
if len(result) == 0:
    if min(t) < min(r):
        print(min(t),min(r),sep='')
    else:
        print(min(r),min(t),sep='')
else:
    print(min(result))