
import sys

arr = list(map(int,input().split()))
n = arr[0]
m = arr[1]

n_arr = list(map(int,input().split()))
m_arr = list(map(int,input().split()))

n_arr.sort()
m_arr.sort()

short_arr = []
long_arr = []

if m > n : 
    short_arr = n_arr
    long_arr = m_arr
else:
    short_arr = m_arr
    long_arr = n_arr

for i in long_arr:
    if i in short_arr:
        print(i)
        sys.exit(0)
    
print(min(str(short_arr[0])+str(long_arr[0]),str(long_arr[0]) + str(short_arr[0])))
