#include <bits/stdc++.h>
using namespace std;
int main()
{
string a,b,r;
cin >> a;
cin >> b;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
while (a.length() != 0 & b.length() != 0)
{
char s = b[0];
if (a.find(s) != -1)
{
r = r + s;
}
while (a.find(s) != -1)
a.erase(a.find(s),1);
while (b.find(s) != -1)
b.erase(b.find(s),1);
}
sort(r.begin(),r.end());
if (r.length() == 0)
cout << 0;
else cout << r << endl;
}