# -*- coding:utf-8 -*-
#[n, m] = [int(x) for x in raw_input().split()]

def some_func():
    """
    """
    n,m = [int(x) for x in raw_input().split()]
    n_list = [int(x) for x in raw_input().split()]
    m_list = [int(x) for x in raw_input().split()]
    f1,f2 =0,0
    for i in range(1,10):
        if i in n_list:
            f1=i
            break
    for i in range(1,10):
        if i in m_list:
            f2=i
            break
    if f1==f2:
        return f1
    elif f1<f2:
        return f1*10+f2
    else:
        return f2*10+f1



if __name__ == '__main__':
    print some_func()



