a, b = input().split()
fi = [int(i) for i in input().split()]
se = [int(i) for i in input().split()]
fi.sort();
se.sort();
for i in fi:
    if i in se:
        print(i);
        exit(0);
print(min(fi[0], se[0]), max(fi[0], se[0]), sep='')