n,m = input().split()
A = input().split()
B = input().split()
n = len(A)
m = len(B)
if min(B) in min(A):
    ans = (str(min(A)))
    print(ans)
else :
    ans = (str(min(A)))+(str(min(B)))
    print(ans)
