var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function lower_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<e?a=c:b=c;return d[a]<e?b:a};

console.log(main());
function main(){
  var s = o.a(1);
  var t = o.a(1);
  var sl = s.length;
  var tl = t.length;
  var dp = [[-1,""]];
  var u = Array(26).fill(0).map(a=>[]);
  for(var i = 0; i < sl; i++){
    u[s[i].charCodeAt()-97].push(i);
  }
  for(i = 0; i < tl; i++){
    var sn = u[t[i].charCodeAt()-97];
    for(var j = dp.length-1; j >= 0; j--){
      var v = lower_bound(sn,0,sn.length,dp[j][0]+1);
      if(v !== sn.length){
        if(dp[j+1] === undefined)dp[j+1] = [sn[v], dp[j][1]+t[i]];
        else if(sn[v] < dp[j+1][0])dp[j+1] = [sn[v], dp[j][1]+t[i]];
      }
    }
  }
  return dp[dp.length-1][1];
}