import sys
import math
import bisect
import itertools

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    '''
    print('A: ' + str(A))
    print('B: ' + str(B))
    '''
    min_val = 10 ** 18
    for i in range(1, 100):
        f1 = False
        f2 = False
        for c in str(i):
            if int(c) in A:
                f1 = True
            if int(c) in B:
                f2 = True
        if f1 and f2:
            val = i
            min_val = min(min_val, val)
    print(min_val)

if __name__ == "__main__":
    main()
