#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define F first
#define S second
#define loop(a,n) for(int i=a; i<=n ; i++)
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define NAME "NUMBER"
using namespace std;
string x,y,t1,t2,t3;
string dp[205][205];
int m,n;
string maxs(string a, string b) {
    if (a.size() > b.size()) return a;
    if (a.size() < b.size()) return b;
    return max(a,b);
}
string xoa0(string s) {
    int i = 0;
    while (i < s.size() - 1 && s[i] == '0') i++;
    return s.substr(i);
}

void nhap() {
    cin >> x >> y;
    m = x.size();
    n = y.size();
}

void solve() {
    for (int i = m; i >= 0; --i) {
        for (int j = n; j >= 0; --j) {
            if (i == m || j == n) dp[i][j] = "";
            else if (x[i] == y[j]) {
                t1 = x[i] + dp[i + 1][j + 1];
                t2 = dp[i + 1][j];
                t3 = dp[i][j + 1];
                dp[i][j] = maxs(t1, maxs(t2, t3));
            } else {
                dp[i][j] = maxs(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }

    string res = xoa0(dp[0][0]);
    if (res.empty()) cout << -1 << endl;
    else cout << res << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen(NAME".INP","r",stdin);
    freopen(NAME".OUT","w",stdout);
    nhap();
    solve();
    return 0;
}
