n, m = map(int, raw_input().split())

a = map(int, raw_input().split())
b = map(int, raw_input().split())

a.sort()
b.sort()
if a[0] == b[0]: print a[0]
else: print "%d%d" %(min(a[0], b[0]), max(a[0], b[0]))