#include<iostream>
using namespace std;
int main()
{
while (true) {
long long int ct[26] = { 0 };
long long int ct2[26] = { 0 };
char cc;
while (true) {
scanf("%c", &cc);
if (cc < 'a' || cc>'z') { break; }
else {
for (int i = 0;i < 26;i++)
{
if (i == cc - 'a') { ct[i]++; }
}
}
}
while (true) {
scanf("%c", &cc);
if (cc < 'a' || cc>'z') { break; }
else {
for (int i = 0;i < 26;i++)
{
if (i == cc - 'a') { ct2[i]++; }
}
}
}
for (int i = 0;i < 26;i++)
{
if (ct[i] != 0 && ct2[i] != 0) {
if (ct[i] > ct2[i]) { while (ct2[i]--) { printf("%c", char(i + 'a')); } }
else { while (ct[i]--) { printf("%c", char(i + 'a')); } }
}
}
cout << endl;
}
}