#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define FI first
#define SE second
#define MP make_pair
#define ALL(DATAST) DATAST.begin(), DATAST.end()
#define MOD 1000000007ll
#define SIZE 100100ll

ll dp[1050][1050];


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    string x, y;

    cin >> x >> y;


    ll m = x.length();
    ll n = y.length();

    memset(dp, 0, sizeof(dp));

    for (ll i = 1; i <= m; i++)
    {
        for (ll j = 1; j <= n; j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);

            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }

    string ans = "";

    ll c = n;
    ll r = m;

    while(c>0 && r>0)
    {
        if(x[r-1]==y[c-1])
        {
            ans = x[r-1]+ans;
            r--;
            c--;
        }
        else if(dp[r][c]==dp[r-1][c])
            r = r-1;
        else if(dp[r][c]==dp[r][c-1])
            c = c-1;
    }



    cout<<ans;

    return 0;


}