print((lambda a,x,y: sorted([i for i in x if i in y])[0] if len([i for i in x if i in y])!=0 else str(min(min(x),min(y)))+str(max(min(x),min(y))))(input(),list(map(int,input().split())),list(map(int,input().split()))))