#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <string>
#include <queue>

using namespace std;

struct sym
{
    char s;
    int id;
    sym();
    sym(char s, int id): s(s), id(id) {};
    bool operator<(sym b) const
    {
        return (s < b.s) || (s == b.s && id > b.id);    
    }
};

int main()
{
    freopen("name.in", "r", stdin);
    freopen("name.out", "w", stdout);
    string s, t;
    cin >> s >> t;
    priority_queue<sym> p1, p2;
    for (int i = 0; i < s.length(); i++)
		p1.push(sym(s[i], i));

    for (int i = 0; i < t.length(); i++)
        p2.push(sym(t[i], i));

	string ans = "";
	int cur1 = 0, cur2 = 0;

	while (!p1.empty() && !p2.empty())
	{
		if (p1.top().s == p2.top().s)
		{
			cur1 = p1.top().id, cur2 = p2.top().id;
			ans += p1.top().s;
			p1.pop(), p2.pop();
		}
		while (!p1.empty() && p1.top().s > p2.top().s) p1.pop();
		while (!p2.empty() && p1.top().s < p2.top().s) p2.pop();
		while (!p1.empty() && p1.top().id < cur1) p1.pop();
		while (!p2.empty() && p2.top().id < cur2) p2.pop();
	}
	cout << ans << endl;
}
