#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[1005],b[1005],ans[1005];
int dp[1005][1005];
int main()
{
//freopen("input.txt","r",stdin);
scanf("%s %s",a+1,b+1);
int n = strlen(a+1);
int m = strlen(b+1);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i] == b[j]){
dp[i][j] = dp[i-1][j-1] + 1;
}else{
dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
}
}
}
int cur = 0;
for(int i=n,j=m;dp[i][j];--i,--j){
while(dp[i][j] == dp[i-1][j]) --i;
while(dp[i][j] == dp[i][j-1]) --j;
ans[cur++] = a[i];
}
reverse(ans,ans+cur);
//ans[cur] = '\0';
printf("%s\n",ans);
return 0;
}
using namespace std;
typedef long long ll;
char a[1005],b[1005],ans[1005];
int dp[1005][1005];
int main()
{
//freopen("input.txt","r",stdin);
scanf("%s %s",a+1,b+1);
int n = strlen(a+1);
int m = strlen(b+1);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i] == b[j]){
dp[i][j] = dp[i-1][j-1] + 1;
}else{
dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
}
}
}
int cur = 0;
for(int i=n,j=m;dp[i][j];--i,--j){
while(dp[i][j] == dp[i-1][j]) --i;
while(dp[i][j] == dp[i][j-1]) --j;
ans[cur++] = a[i];
}
reverse(ans,ans+cur);
//ans[cur] = '\0';
printf("%s\n",ans);
return 0;
}