#!/usr/bin/env python3

def m(s1, s2):
    si = s1.intersection(s2)
    if si:
        return min(si)
    smin, smax = sorted(map(min, (s1, s2)))
    return smin * 10 + smax

if __name__ == "__main__":
    input()
    print(m(*(set(map(int, input().split())) for i in range(2))))
