n, m = list(map(int, input().split()))
a = set(map(int, input().split()))
b = set(map(int, input().split()))
common = a&b
if len(common) > 0:
    print(min(common))
else:
    am = min(a)
    bm = min(b)
    print("{}{}".format(min(am, bm), max(am, bm)))
