INF = int(10000000009)

while True:
    try:
        n,m = map(int,input().split())

        a = []
        b = []
        mina = int(INF)
        minb = int(INF)

        for i in input().split():
            a.append(int(i))
            mina = min(mina,int(i))

        for i in input().split():
            b.append(int(i))
            minb = min(minb,int(i))

        flag = False
        mark = int(INF)

        for i in range(0,len(a)):
            for j in range(0,len(b)):
                if a[i] == b[j]:
                    mark = min(mark,a[i])
                    flag = True

        if mina == minb:
            print(mina)
        else:
            if flag:
                print(mark)
            else:
                max2 = max(mina,minb)
                min2 = min(mina,minb)
                min2 = int(min2) * 10
                max2 = int(max2)
                ans = int(min2 + max2)
                print(ans)
    except:
        break
					 			  									  		 		 		