def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A = sorted(A)
    B = sorted(B)
    for i in A:
        for j in B:
            if i == j:
                print(i)
                return
    print(min(A[0], B[0]), max(A[0], B[0]), sep='')


if __name__ == '__main__':
    main()
