import sys
import itertools

def main():
    n, m = map(int, raw_input().split())
    A = map(int, raw_input().split())
    B = map(int, raw_input().split())
    
    ar = list(itertools.product(A, B))
    ar = map(lambda x: int(x[0]) if x[0] == x[1] else int(x[0])*10 + int(x[1]), ar)
    print sorted(ar)[0]
    
    
if __name__ == '__main__':
    main() 
    
