//giving runerror in 2 cases
#include<bits/stdc++.h>
using namespace std;
int main() {
string str1,str2;
long int i,i1,i2,v,n,ans,f1,f2;
ans=1000000;
long int M1[2000]={0};
long int M2[2000]={0};
getline (std::cin,str1);
getline (std::cin,str2);
//cout<<str1<<endl;
for(i=0;i<str2.length();i++)
{
M2[str2[i]]++;
}
n=str1.length();
i1=0;
i2=0;v=0;
while(i2!=n)
{
M1[str1[i2]]++;
if(M1[str1[i2]]<=M2[str1[i2]])
{
v++;}
//cout<<M1[str1[i1]]<<"+"<<M2[str1[i1]]<<endl;
while(M1[str1[i1]]>M2[str1[i1]])
{
M1[str1[i1]]--;
i1++;
}
if(str2.length()<=v)
{
if(i2-i1<ans)
{
ans=i2-i1;
f1=i1;
f2=i2;
//cout<<f1<<f2<<endl;
}
}
i2++;
}
cout<<str1.substr(f1,f2-f1+1);
return 0;
}
//giving runerror in 2 cases