# -*- 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()]

    n_list.sort()
    m_list.sort()
    for i in range(1,10):
        if i in n_list and i in m_list:
            return i
    f1,f2 = n_list[0],m_list[0]

    if f1<f2:
        return f1*10+f2
    else:
        return f2*10+f1



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



