# -*- coding: utf-8 -*-
"""
Created on Mon Oct 23 10:53:48 2017

@author: Paras
"""

a=input()
a=a.split()
b=input()
b=b.split()
c=input()
c=c.split()
b.sort()
c.sort()
z=0
for i in b:
    if z==0:
        if i in c:
            print(int(i))
            z=1
if z==0:    
    d=min(b)
    e=min(c)
    if d==e:
        print(int(d))
    else:
        x=(int(str(d)+str(e)))
        y=int(str(e)+str(d))
        if x<y:
            print(x)
        else:
            print(y)