//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    int sum = 0;
    for(int i = '1'; i <= '9'; ++i)++sum;
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i, tsum = sum;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
            if(x % 10)
                --tsum;
        }
        bool flag = (i + tot == n) && !(tsum == 0 && ss[0] == '0' && m != 1);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
    bool first = true;
    for(int i = '0'; i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
    n = 0;
    if(sum == 0 || first)
    {
        for(int c = '0'; c <= '9'; ++c)
		{
			while(cnt[c]--)
			{
				ss[m++] = c;
			}
		}
        puts(ss);
        return 0;
    }
    bool dec = true;
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(ss[0] == '0' || !dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128], sum;
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i, tsum = sum;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
            if(x % 10) --tsum;
        }
        bool flag = (i + tot == n) && !(tsum == 0 && ss[0] == '0' && m != 1);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    sum = 0;
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    for(int i = '1'; i <= '9'; ++i) ++sum;
    deal_length();
    bool dec = ss[0] != '0';
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    bool first = dec;
    for(int i = '1'; first && i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
    n = 0;
    sum = 0;
    for(int i = '1'; i <= '9'; ++i) ++sum;
    if(sum == 0 || first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--)
            {
                ss[m++] = c;
            }
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(--cnt[c]) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(--cnt[c]) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128], sum;
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i, tsum = sum;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
            if(x % 10) --tsum;
        }
        bool flag = (i + tot == n) && !(tsum == 0 && ss[0] == '0' && m != 1);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    sum = 0;
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    for(int c = '1'; c <= '9'; ++c) sum += cnt[c];
    deal_length();
    bool dec = ss[0] != '0';
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    bool first = dec;
    for(int i = '1'; first && i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
    sum = 0;
    for(int c = '1'; c <= '9'; ++c) sum += cnt[c];
    if(sum == 0 || first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) ss[m++] = c;
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    m = strlen(ss);
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    for(int i = 1; i <= n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(n == 0)
    {
        for(int i = 0; i < cnt['0']; ++i)
            ss[m++] = '0';
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    bool dec = true;
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    if(ss[0] == '0' || !dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = true;
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    n = 0;
    for(int i = 0; i < m; ++i) ans[n++] = ss[i];
    for(int c = '0'; c <= '9'; ++c)
    {
        for(int i = 0; i < cnt[c]; ++i) ans[n++] = c;
    }
    ans[n] = 0;
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(n == 0)
	{
		puts(ans);
		return 0;
	}
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    if(ans[0] != '0' && strcmp(ans, s) <= 0)
		puts(ans);
	else
		puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    n = 0;
    for(int i = 0; i < m; ++i) ans[n++] = ss[i];
    for(int c = '0'; c <= '9'; ++c)
    {
        while(cnt[c]--) ans[n++] = c;
    }
    ans[n] = 0;
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(n == 0)
	{
		puts(ans);
		return 0;
	}
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    if(strcmp(ans, s) <= 0)
		puts(ans);
	else
		puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    int sum = 0;
    for(int i = '1'; i <= '9'; ++i)++sum;
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i, tsum = sum;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
            if(x % 10)
                --tsum;
        }
        bool flag = (i + tot == n) && !(tsum == 0 && ss[0] == '0' && m != 1);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
    bool dec = true;
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    bool first = dec;
    for(int i = '0'; first && i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
    n = 0;
    if(sum == 0 || first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--)
            {
                ss[m++] = c;
            }
        }
        puts(ss);
        return 0;
    }
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(ss[0] == '0' || !dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    if(m > 20)
    {
        puts(ss);
        return 0;
    }
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    bool first = true;
    for(int i = '1'; i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
	first = first && ss[0] != '0' && (cnt[ss[0]] == 0 || dec);
    if(first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) ss[m++] = c;
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int kmp[NUM];
int n, m;
int KMP()
{
    int i, j;
    j = kmp[i = 0] = -1;
    while(i < m)
    {
        while(j != -1 && ss[i] != ss[j]) j = kmp[j];
        if(ss[++i] == ss[++j]) kmp[i] = kmp[j];
        else kmp[i] = j;
    }
    i = 0, j = 0;
    while(i < n)
    {
        while(j != -1 && s[i] != ss[j]) j = kmp[j];
        ++i, ++j;
        if(s[i] > ss[j])
        {
            return i - j;
        }
        if(j == m)
        {
            j = kmp[j];
        }
    }
    return n;
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    m = strlen(ss);
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    for(int i = 1; i <= n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
        	++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(n == 0)
    {
        for(int i = 0; i < cnt['0']; ++i)
            ss[m++] = '0';
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    if(ss[0] == '0')
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            for(int i = 0; i < cnt[c]; ++i)
            {
                s[n++] = c;
            }
            if(c == '0')
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
        s[n] = 0;
        puts(s);
        return 0;
    }
    for(char c = '0'; c <= '9'; ++c)
    {
        for(int i = 0; i < cnt[c]; ++i)
        {
            s[n++] = c;
        }
    }
    s[n] = 0;
    int p = KMP();
//    puts(s);
//    puts(ss);
//    printf("pos = %d\n", p);
    int k = 0;
    for(int i = 0; i < p; ++i)
		ans[k++] = s[i];
	for(int i = 0; i < m; ++i)
		ans[k++] = ss[i];
	for(int i = p; i < n; ++i)
		ans[k++] = s[i];
	ans[k] = 0;
	puts(ans);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128], sum;
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i, tsum = sum;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
            if(x % 10) --tsum;
        }
        bool flag = (i + tot == n) && !(tsum == 0 && ss[0] == '0' && m != 1);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    sum = 0;
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    for(int i = '1'; i <= '9'; ++i) ++sum;
    deal_length();
    bool dec = ss[0] != '0';
    for(int i = 1; i < m; ++i)
        if(ss[i] != ss[i - 1])
        {
            dec = ss[i] < ss[i - 1];
            break;
        }
    bool first = dec;
    for(int i = '1'; first && i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
    n = 0;
    sum = 0;
    for(int i = '1'; i <= '9'; ++i) if(cnt[i]) ++sum;
    if(sum == 0 || first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--)
            {
                ss[m++] = c;
            }
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    bool first = true;
    for(int i = '1'; i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
	first = first && (cnt[ss[0]] == 0 || dec);
    if(first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) ss[m++] = c;
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    n = 0;
    for(int i = 0; i < m; ++i) ans[n++] = ss[i];
    for(int c = '0'; c <= '9'; ++c)
    {
        for(int i = 0; i < cnt[i]; ++i) ans[n++] = c;
    }
    ans[n] = 0;
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(n == 0)
	{
		puts(ans);
		return 0;
	}
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    if(ans[0] != '0' && strcmp(ans, s) <= 0)
		puts(ans);
	else
		puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            return ;
        }
    }
    assert(false);
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    bool first = true;
    for(int i = '1'; i < ss[0]; ++i)
        if(cnt[i])
        {
            first = false;
            break;
        }
	first = first && ss[0] != '0' && (cnt[ss[0]] == 0 || dec);
    if(first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) ss[m++] = c;
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


//writed by dnvtmf
#include <bits/stdc++.h>
#define INF 1000000007
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 1000010;
char s[NUM], ss[NUM], ans[NUM];
int cnt[128];
int n, m;

void deal_length()
{
    for(int i = 1; i < n; ++i)
    {
        int num[10] = {}, tot = 0;
        int x = i;
        while(x)
        {
            ++tot;
            ++num[x % 10];
            x /= 10;
        }
        bool flag = (i + tot == n);
        for(int j = 0; flag && j < 10; ++j)
            if(num[j] > cnt[j + '0'])
            {
                flag = false;
            }
        if(flag)
        {
//            printf("n = %d\n", i);
            for(int j = 0; j < 10; ++j)
                cnt[j + '0'] -= num[j];
            break;
        }
    }
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//  freopen("in.txt", "w", stdout);
#endif
    scanf("%s %s", s, ss);
    n = strlen(s);
    m = strlen(ss);
    for(int i = 0; i < n; ++i) ++cnt[s[i]];
    for(int i = 0; i < m; ++i) --cnt[ss[i]];
    deal_length();
    bool dec = ss[0] != '0';
    if(dec)
    {
        for(int i = 1; i < m; ++i)
            if(ss[i] != ss[i - 1])
            {
                dec = ss[i] < ss[i - 1];
                break;
            }
    }
    bool first = dec;
    if(first)
    {
        for(int i = '1'; i < ss[0]; ++i)
            if(cnt[i])
            {
                first = false;
                break;
            }
    }
    if(first)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) ss[m++] = c;
        }
        ss[m] = 0;
        puts(ss);
        return 0;
    }
    n = 0;
    for(int c = '1'; c <= '9'; ++c)
    {
        if(cnt[c] > 0)
        {
            s[n++] = c;
            --cnt[c];
            break;
        }
    }
    if(dec)
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
            while(cnt[c]--) s[n++] = c;
        }
    }
    else
    {
        for(int c = '0'; c <= '9'; ++c)
        {
            while(cnt[c]--) s[n++] = c;
            if(c == ss[0])
            {
                for(int i = 0; i < m; ++i)
                {
                    s[n++] = ss[i];
                }
            }
        }
    }
    s[n] = 0;
    puts(s);
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		string tmp = "";
		auto save = now;
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); ~cur; cur = _next(now)) {
			now[cur]--; tmp2 += (char)(cur + '0');
		}
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(~id) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); ~cur; cur = _next(now)) {
			now[cur]--; tmp2 += (char)(cur + '0');
		}
		if(y[0] == '0') tmp2 = "z";
		if(tmp[0] == '0') tmp ="z";
		// cerr << tmp << ' '<< tmp2 << nxtl;
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1) continue;
		tmp += (char)(id + '0'); now[id]--;
		id = _next(now, -1, y[0]-'0'+(nq < sz(y) && y[0] < y[nq]));
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now, -1, y[0] - '0' + (nq < sz(y) && y[0] < y[nq]));
		}
		tmp += y;
		id = _next(now);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now);
		}
		return tmp;
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) { if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		const auto &save = now;
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
			now[cur]--, tmp2 += (char)(cur + '0');
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(id != -1) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
		  now[cur]--, tmp += (char)(cur + '0');
		if(y[0] == '0') tmp2 = "z";	if(tmp[0] == '0') tmp = "z";
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		auto save = now;
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); cur != -1; cur = _next(now)) {
			now[cur]--; tmp2 += (char)(cur + '0');
		}
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(id != -1) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); cur != -1; cur = _next(now)) {
			now[cur]--; tmp += (char)(cur + '0');
		}
		if(y[0] == '0') tmp2 = "z";
		if(tmp[0] == '0') tmp ="z";
		cerr << tmp << ' '<< tmp2 << nxtl;
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		int taken = 0;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		if(id != -1 && (nq == sz(y) || y[nq] > y[0])) tmp += (char)(id + '0'), now[id]--;
		else tmp += y, taken = 10;
		id = _next(now, -1, y[0]-'0'+(nq < sz(y) && y[0] < y[nq])+taken);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now, -1, y[0] - '0' + (nq < sz(y) && y[0] < y[nq])+taken);
		}
		if(!taken)
			tmp += y;
		id = _next(now);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now);
		}
		return tmp;
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

string s, ss;

int kol[10], q[10], b, n, fst;

inline bool check(int x) {
  memset(q, 0, sizeof q);
	while (x) {
		q[x % 10]++;
		x /= 10;
	}
	rep(i, 0, 9) if (kol[i] < q[i]) return 0;
	return 1;
}

inline void del(int x) {
	while (x) {kol[x % 10]--; x /= 10;}
}
inline int L(int x) {
  int res = 0;
	while (x) {res++; x /= 10;}
	return res;
}

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
//	freopen(fname".in", "r", stdin);
	//freopen(fname".out", "w", stdout);
	cin >> s >> ss;
	fst = ss[0] - '0';
	n = sz(s);
	rep(i, 0, sz(s) - 1) kol[s[i] - '0']++;
	rep(i, 0, sz(ss) - 1) kol[ss[i] - '0']--;
	rep(i, 0, sz(ss) - 1) {
		if (ss[i] < ss[i + 1]) {
			b = 1; break;
		}
		if (ss[i] > ss[i + 1]) break;
	}
	rep(len, 1, n-1) {
		if (check(n - len) && len == L(n - len)) {
			del(n - len);
			bool bol = 1;
			rep(i, 1, 9) if (kol[i]) {
			  kol[i]--;
				cout << i;
				bol = 0;
				break;
			}
			if (bol && ss == "0") {
				cout << 0;
				return 0;
			}
			rep(i, bol, 9) {
				if (i == fst) {
					if (b) {
						while(kol[i]-->0) cout << i;
						cout << ss;
					}else {
						cout << ss;
						while (kol[i]-->0) cout << i;
					}
				}else {
					while (kol[i]-->0) cout << i;
				}
			}
			while (kol[0]-->0) cout << 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		int taken = 0;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		int found = 0;
		while(found < sz(y) && y[found] == id+'0') found++;
		if(id != -1 && (found == sz(y) || y[found] > id+'0' || y[0] == '0')) tmp += (char)(id + '0'), now[id]--;
		else tmp += y, taken = 10;
		id = _next(now, -1, y[0]-'0'+(nq < sz(y) && y[0] < y[nq])+taken);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now, -1, y[0] - '0' + (nq < sz(y) && y[0] < y[nq])+taken);
		}
		if(!taken)
			tmp += y;
		id = _next(now);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now);
		}
		return tmp;
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		int taken = 0;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		int found = 0;
		while(found < sz(y) && y[found] == id+'0') found++;
		if(id != -1 && (found == sz(y) || y[found] > id+'0')) tmp += (char)(id + '0'), now[id]--;
		else tmp += y, taken = 10;
		id = _next(now, -1, y[0]-'0'+(nq < sz(y) && y[0] < y[nq])+taken);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now, -1, y[0] - '0' + (nq < sz(y) && y[0] < y[nq])+taken);
		}
		if(!taken)
			tmp += y;
		id = _next(now);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now);
		}
		return tmp;
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) { if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		auto save = now;
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
			now[cur]--, tmp2 += (char)(cur + '0');
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(id != -1) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
		  now[cur]--, tmp += (char)(cur + '0');
		if(y[0] == '0') tmp2 = "z";	if(tmp[0] == '0') tmp = "z";
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) { if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		save = now;
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
			now[cur]--, tmp2 += (char)(cur + '0');
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(id != -1) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
		  now[cur]--, tmp += (char)(cur + '0');
		if(y[0] == '0') tmp2 = "z";	if(tmp[0] == '0') tmp = "z";
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) {
			if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		if(!ok || n - kol != i) continue;
		bool taken = 0;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		if(id != -1) tmp += (char)(id + '0'), now[id]--;
		else tmp += y, taken = 1;
		id = _next(now, -1, y[0]-'0'+(nq < sz(y) && y[0] < y[nq]));
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now, -1, y[0] - '0' + (nq < sz(y) && y[0] < y[nq]));
		}
		if(!taken)
			tmp += y;
		id = _next(now);
		while(id != -1) {
			now[id]--;
			tmp += (char)(id + '0');
			id = _next(now);
		}
		return tmp;
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(),s.end()
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
	rep(i, 0, 9) if(x[i] > 0 && i != cant && i < low) return i;
	return -1;
}

inline string f(const string &x, const string &y) {
	if(x == "10" || x == "01") return "0";
	int n = sz(x);
	vector < int > cnt(10, 0);
	for(auto &to : x) cnt[to - '0']++;
	for(auto &to : y) cnt[to - '0']--;
	int nq = 0;
	while(nq < sz(y) && y[0] == y[nq]) nq++;
	rep(i, 1, n-1) {
		vector < int> now = cnt;
		int I = i, kol = 0;
		bool ok = 1;
		while(I) { if(!now[I % 10]) ok = 0;
			now[I % 10]--;
			kol++;
			I /= 10;
		}
		const auto &save = now;
		if(!ok || n - kol != i) continue;
		string tmp = "";
		int id = _next(now, 0);
		if(id == -1 && y[0] == '0') continue;
		string tmp2 = y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
			now[cur]--; tmp2 += (char)(cur + '0');
		if(id == -1) return tmp2;
		now = save;
		tmp += (char)(id + '0'), now[id]--;
		bool must = (nq == sz(y) || y[nq] > y[0]);
		id = _next(now, -1, y[0] - '0' + must);
		while(id != -1) {
			tmp += (char)(id + '0');
			now[id]--;
			id = _next(now, -1, y[0] - '0' + must);
		}
		tmp += y;
		for(int cur = _next(now); cur != -1; cur = _next(now))
		  now[cur]--, tmp += (char)(cur + '0');
		if(y[0] == '0') tmp2 = "z";	if(tmp[0] == '0') tmp = "z";
		return min(tmp, tmp2);
	}
	assert(false);
}
string s, k;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	cin >> s >> k;
	cout << f(s, k) << nxtl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else if(g[i]<g[i-1])f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=7;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<10;i++)
                if((g[0]-'0'==i&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       int fg=0;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
       if(g[i]=='0')fg++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&fg>flag[0]&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=7;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<10;i++)
                if((g[0]-'0'==i&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       int fg=0,lg=1;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
       if(g[i]=='0'&&lg==1)fg++;
       else lg=0;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&(fg>flag[0]||flag[0]==0)&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       int fg=0,lg=1;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
       if(g[i]=='0'&&lg==1)fg++;
       else lg=0;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&fg>flag[0]&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<10;i++)
                if((g[0]-'0'==i&&flag[0]==0&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&(flag[0]==0||g[1]=='0')&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=7;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[gg%10]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i)
                {
                    if(f==1)
                        {printf("%s",g);
                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
                        }
                        else
                        {
                          for(int j=1;j<=flag[i];j++)
                        cout<<i;
                        printf("%s",g);
                        }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
                }
            }
            cout<<endl;
        }
        else
        {
            int flv=1;
            for(int i=1;i<10;i++)
                if(g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&flag[0]==0&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)
#define lowbit(x) ((x)&(-x))
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e6+100 , mxn = 5e5 +100;
const ld PI = acos(-1.0);
ll gcd (ll a, ll b)
{return ( a ? gcd(b%a, a) : b );}
void exgcd(ll a,ll b,ll &d,ll& x,ll& y)
{
    if(!b){d=a;x=1;y=0;}
    else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
}
ll power(ll a, ll n)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head
int n,m,k;
char s[maxn],g[maxn];
int flag[20],ff[20];
int main()
{
    while(~scanf("%s",s))
    {
       scanf("%s",g);
       int f=0;
       memset(flag,0,sizeof flag);memset(ff,0,sizeof ff);
       int len1=strlen(s),len2=strlen(g);
       ff[g[0]-'0']++;
       int fg=0;
       for(int i=1;i<len2;i++)
        {if(g[i]!=g[i-1]&&f==0)
       {
           if(g[i]>g[i-1])f=2;
           else f=1;
       }
       ff[g[i]-'0']++;
       if(g[i]!='0')fg=1;
        }
        if(f==0)f=1;
        for(int i=0;i<len1;i++)
            flag[s[i]-'0']++;
        int t=0;
        for(int i=1;i<=8;i++)
            if(len1-i>=pow(10,i-1)&&len1-i<pow(10,i))
        {
            t=i;break;
        }
        int gg=len1-t;
        while(gg>0)
        {
            flag[(gg%10)]--;
            gg/=10;
        }
        for(int i=0;i<10;i++)
            flag[i]-=ff[i];
        if(g[0]=='0')
        {
            for(int i=1;i<10;i++)
                if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(i==1)
                {
                    printf("%s",g);
                }

                    for(int j=1;j<=flag[i];j++)
                        cout<<i;
            }
        }
        else
        {
            int flv=1;
            for(int i=1;i<=10;i++)
                if((g[0]-'0'==i&&(flag[0]==0||fg==0)&&f==1)||g[0]-'0'<i)
            {
                printf("%s",g);flv=0;break;
            }
            else if(flag[i]>0)
            {
                cout<<i;flag[i]--;break;
            }
            for(int i=0;i<10;i++)
            {
                if(g[0]-'0'==i&&flv==1)
                {
                    if(f==1)
                    {
                        printf("%s",g);
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                    }
                    else
                    {
                        for(int j=1;j<=flag[i];j++)
                            cout<<i;
                            printf("%s",g);
                    }
                }
                else
                {
                    for(int j=1;j<=flag[i];j++)
                            cout<<i;
                }
            }
        }
        cout<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

int Am[15], F[1000005];
string S, T, Sub;

int main()
{
    cin >> S >> Sub;
    if(S == "0" || S == "00" || S == "01" || S == "10")
    {
        cout << "0";
        return 0;
    }
    f(i,0,SZ(S)-1) Am[S[i]-'0']++;
    f(i,0,SZ(Sub)-1) Am[Sub[i]-'0']--;
    int fin = 1, q = 1;
    f(k,1,1000000)
    {
        if(k == 10) q++;
        if(k == 100) q++;
        if(k == 1000) q++;
        if(k == 10000) q++;
        if(k == 100000) q++;
        if(k == 1000000) q++;
        int total = k + q;
        if(total == SZ(S))
        {
            fin = k;
            break;
        }
    }
    while(fin)
    {
        int dig = fin%10;
        Am[dig]--;
        fin /= 10;
    }
    string s1 = Sub;
    f(dig,0,9) f(x,1,Am[dig]) s1 += (char) (dig+'0');
    if(Sub[0] == '0') s1 = "A";
    f(dig,1,9) if(Am[dig])
    {
        Am[dig]--;
        T += (char) (dig+'0');
        break;
    }
    f(dig,0,9) f(x,1,Am[dig]) T += (char) (dig+'0');
    if(T.empty())
    {
        cout << Sub;
        return 0;
    }
    //cout << T << "\n" << Sub << "\n\n";
    string s2 = T + Sub;
    if(s2[0] == '0') s2 = "A";
    string s3 = "A";
    f(i,1,SZ(T)-1)/* if(T[i] != T[i-1])*/
    {
        string temp = T.substr(0,i) + Sub + T.substr(i);
        //cout << temp << "\n";
        s3 = min(s3,temp);
    }
    string s4 = SZ(T) >= 2 ? T.substr(0,1) + Sub + T.substr(1) : "A";
    cout << min(min(min(s1,s2),s3),s4);
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

int Am[15], F[1000005];
string S, T, Sub;

int main()
{
    cin >> S >> Sub;
    if(S == "0" || S == "00" || S == "01" || S == "10")
    {
        cout << "0";
        return 0;
    }
    f(i,0,SZ(S)-1) Am[S[i]-'0']++;
    f(i,0,SZ(Sub)-1) Am[Sub[i]-'0']--;
    int fin = 1, q = 1;
    f(k,1,1000000)
    {
        if(k == 10) q++;
        if(k == 100) q++;
        if(k == 1000) q++;
        if(k == 10000) q++;
        if(k == 100000) q++;
        if(k == 1000000) q++;
        int total = k + q;
        if(total == SZ(S))
        {
            fin = k;
            break;
        }
    }
    while(fin)
    {
        int dig = fin%10;
        Am[dig]--;
        fin /= 10;
    }
    string s1 = Sub;
    f(dig,0,9) f(x,1,Am[dig]) s1 += (char) (dig+'0');
    if(Sub[0] == '0') s1 = "A";
    f(dig,1,9) if(Am[dig])
    {
        Am[dig]--;
        T += (char) (dig+'0');
        break;
    }
    f(dig,0,9) f(x,1,Am[dig]) T += (char) (dig+'0');
    if(T.empty())
    {
        cout << Sub;
        return 0;
    }
    //cout << T << "\n" << Sub << "\n\n";
    string s2 = T + Sub;
    if(s2[0] == '0') s2 = "A";
    string s3 = "A";
    f(i,1,SZ(T)-1) if(T[i] != T[i-1])
    {
        string temp = T.substr(0,i) + Sub + T.substr(i);
        //cout << temp << "\n";
        s3 = min(s3,temp);
    }
    string s4 = SZ(T) >= 2 ? T.substr(0,1) + Sub + T.substr(1) : "A";
    if(s4[0] == '0') s4 = "A";
    /*cout << s1 << "\n";
    cout << s2 << "\n";
    cout << s3 << "\n";
    cout << s4 << "\n";*/
    cout << min(min(min(s1,s2),s3),s4);
}


#include <iostream>
using namespace std;

int main() {
    string s;
    while (true) {
        cin>>s;
        if (s == "end") {
            break;
        }
        int lo = 0;
        int hi = 1;

        while (true) {
            cout<<"? "<<lo<<" "<<hi<<endl;
            cout<<flush;

            int resp;
            cin>>resp;

            if (resp == hi) {
                lo = hi;
                hi = hi * 2;
            } else {
                break;
            }
        }

        while (lo < hi) {
            int mid = (lo + hi)/2;
            cout<<"? "<<lo<<" "<<mid<<endl;
            cout<<flush;
            int resp;
            cin>>resp;

            if (resp == lo) {
                hi = resp;
            } else {
                lo = mid + 1;
            }
        }
        cout<<"! "<<lo+1<<endl;
        cout<<flush;
    }
}


#include <stdio.h>
#include <iostream>
using namespace std;

typedef long long ll;

char s[100];
char resp[100];

int main() {
    while (true) {
        scanf("%s",s);
        if (s[0] == 'e') {
            fflush(stdout);
            break;
        }
        if (s[0] == 'm') {
            fflush(stdout);
            break;
        }
        ll lo = 0;
        ll hi = 1;

        while (true) {
            printf("? %lld %lld\n", lo, hi);
            fflush(stdout);

            scanf("%s", resp);

            if (resp[0] == 'y') {
                lo = hi;
                hi = hi * 2;
            } else {
                break;
            }
        }

        while (lo < hi) {
            ll mid = (lo + hi)/2;
            printf("? %lld %lld\n", lo, mid);
            fflush(stdout);

            scanf("%s", resp);

            if (resp[0] == 'x') {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }

        printf("! %lld\n", lo);
        fflush(stdout);
    }
}