#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <string>
#include <queue>
#include <assert.h>

using namespace std;

string s1, s2;
string ans;

void go(size_t l1, size_t l2)
{
	if (s1.length() <= l1 || s2.length() <= l2) return;
	vector<int> c1(26), c2(26);
	
	for (size_t i = l1; i < s1.length(); i++)
		c1[s1[i] - 'a']++;
	for (size_t i = l2; i < s2.length(); i++)
		c2[s2[i] - 'a']++;

	char c = '$';
	int cnt = 0;
	for (int i = 25; i > -1; i--)
		if ((c1[i] > 0) && (c2[i] > 0)) 
		{
			cnt = min(c1[i], c2[i]);
			c = char('a' + i);
			break;
		}
    if (c == '$') return;
	for (int i = 0; i < cnt; i++)
		ans += c;
	int cnt1 = cnt;
	int cnt2 = cnt;
	
	while (cnt1 > 0) if (s1[l1++] == c) cnt1--;
	while (cnt2 > 0) if (s2[l2++] == c) cnt2--;
	go(l1, l2);
}

void check(string s, int si)
{
    for (size_t i = 0; i < s.length(); i++)
        assert('a' <= s[i] && s[i] < (char)('a' + si));
}

int main()
{
    freopen("name.in", "r", stdin);
    freopen("name.out", "w", stdout);
    
    cin >> s1 >> s2;
    assert(s1.length() <= 1e3);
    assert(s2.length() <= 1e3);
    check(s1, 26);
    check(s2, 26);

    go(0, 0);
	
    cout << ans << endl;
}
