import sys

sys.stdin = open('name.in')
sys.stdout = open('name.out', 'w')

s = input()
t = input()
poss = 0
post = 0
scount = dict()
tcount = dict()
for c in s:
    scount[c] = scount.get(c, 0) + 1
for c in t:
    tcount[c] = tcount.get(c, 0) + 1
while True:
    for c in 'abcdefghijklmnopqrstuvwxyz'[::-1]:
        if c in scount and scount[c] > 0 and c in tcount and tcount[c] > 0:
            break
    else:
        sys.exit()
    while s[poss] != c:
        scount[s[poss]] -=1
        poss += 1
    poss += 1
    scount[c] -= 1
    while t[post] != c:
        tcount[t[post]] -=1
        post += 1
    post += 1
    tcount[c] -= 1
    print(c, end = '')