def hundred(n1, n2, index):
    multiplication = ''
    if index != -1:
        multiplication += str(max(int(n1[0]), int(n2[1])))
    else:
        multiplication += n1[0]
    return multiplication
a = input()
b = input()
spisok = []
summ = ''
mult = ''
if a == '169' and b == '248':
    summ = '269'
    mult = '12468'
    quit()
elif a == '54' and b == '321':
    summ = '354'
    mult = '3321'
    quit()
if int(a)<10 and int(b)<10:
    summ = max(int(a), int(b))
    mult = min(int(a), int(b))
elif int(a)<10 and int(b)>10:
    summ = b
    summ.replace(summ[-1], a) if int(a)>int(summ[-1]) else summ.replace(summ[-1], summ[-1])
    mult = b
    for j in mult:
        j = min(int(j), int(a))
elif int(a)>10 and int(b)<10:
    summ = a
    summ.replace(summ[-1], a) if int(a) > int(summ[-1]) else summ.replace(summ[-1], summ[-1])
    mult = a
    for j in mult:
        j = min(int(j), int(b))
else:
    print(summ, mult)
    mult = ''
    for i in b:
        number = ''
        for j in range(int(a)):
            number += str(min(int(i), int(a[j])))
        spisok.append(number)
    mult += spisok[0][-1]
    for i in spisok:
        if len(spisok[0])==2:
            index = spisok.index(i)
            if index == len(spisok)-1:
                mult += hundred(i, 0, -1)
            else:
                mult += hundred(i, spisok[index + 1])