#include <iostream>
#include <string>

using namespace std;

int main() {
	string A, B;
	int alp[11] = { 0 };
	int chk[11] = { 0 };

	cin >> A >> B;

	int len = A.length(), l = 1 , r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c; // c는 자릿수

	for (char x : A) alp[x - '0']++;

	if(B.length() != 1) for (char x : B) alp[x - '0']--;

	int temp = c;

	while(temp){
		alp[temp % 10]--;
		temp /= 10;
	}

	for (int i = 1; i < B.length(); i++) {
		if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1; // 마지막에 써야함.
		else chk[B[0] - '0'] = 2; // 처음에 써야함.
		break;
	}

	int flag = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 2) {
				cout << B;
				flag = 1;
			}
			else {
				alp[i]--;
				cout << i; break;
			}
		}
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) cout << i;
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) cout << i;
			}
			else if(flag == 0){
				for (int j = 0; j < alp[i]; j++) cout << i;
				cout << B;
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	int alp[11] = { 0 }, chk[11] = { 0 };

	string A, B; cin >> A >> B;

	int len = A.length(), l = 1, r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c;

	for (char x : A) alp[x - '0']++;
	for (char x : B) alp[x - '0']--;

	int temp = c;

	while (temp) {
		alp[temp % 10]--;
		temp /= 10;
	}

	int sc = 0;
	for (int i = 1; i < B.length(); i++) {
		if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1;
		else chk[B[0] - '0'] = 2;
		sc = 1;
		break;
	}

	if (sc == 0)
		for (char x : B) alp[x - '0']++;

	int flag = 0;
	int first = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 1) {
				// 첫문자 넣을떄 비교...
				int nc = 1, tc = 0;

				for (int j = 0; j <= 9; j++)
					for (int k = 0; k < alp[j]; k++) {
						if (tc != 0) break;
						if (nc == B.length()) tc = 1;
						else if (j > B[nc] - '0') tc = 1;
						else if (j < B[nc] - '0') tc = 2;
						nc++;
					}

				if (tc == 1) {
					cout << B;
					flag = first = 1;
				}
				else {
					alp[i]--;
					first = 1;
					cout << i; break;
				}
			}
			else {
				alp[i]--;
				first = 1;
				cout << i; break;
			}
		}
		else if (chk[i] != 0) {
			cout << B;
			first = 1;
			flag = 1;
		}
	}

	if (first == 0) {
		flag = 1;
		if (B.length() == 1) alp[B[0] - '0']--;
		cout << B;
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) printf("%d", i);
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
			else if (flag == 0) {
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
				cout << B;
			}
			else {
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	string A, B;
	int alp[11] = { 0 };
	int chk[11] = { 0 };

	cin >> A >> B;

	int len = A.length(), l = 1 , r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c; // c는 자릿수

	for (char x : A) alp[x - '0']++;

	if(B.length() != 1) for (char x : B) alp[x - '0']--;

	int temp = c;

	while(temp){
		alp[temp % 10]--;
		temp /= 10;
	}

	for (int i = 1; i < B.length(); i++) {
		if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1;  // 앞 출력
		else chk[B[0] - '0'] = 2;  // 뒤 출력
		break;
	}

	int flag = 0;
	int first = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 1) {
				cout << B;
				flag = first = 1;
			}
			else {
				alp[i]--;
				first = 1;
				cout << i; break;
			}
		}
		else if (chk[i] != 0) {
			cout << B;
			first = 1;
			flag = 1;
		}
	}

	if (first == 0) {
		flag = 1;
		if (B.length() == 1) alp[B[0] - '0']--;
		cout << B;
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) printf("%d", i);
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
			else if(flag == 0){
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
				cout << B;
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	int alp[11] = { 0 }, chk[11] = { 0 };

	string A, B; cin >> A >> B;

	int len = A.length(), l = 1, r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c;

	for (char x : A) alp[x - '0']++;
	for (char x : B) alp[x - '0']--;

	int temp = c;

	while (temp) {
		alp[temp % 10]--;
		temp /= 10;
	}

	int sc = 0;
	for (int i = 1; i < B.length(); i++) {
		if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1;
		else chk[B[0] - '0'] = 2;
		sc = 1;
		break;
	}

	if (sc == 0)
		for (char x : B) alp[x - '0']++;

	int flag = 0;
	int first = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 1) {
				// 첫문자 넣을떄 비교...
				int nc = 1, tc = 0;

				for (int j = 0; j <= 9; j++)
					for (int k = 0; k < alp[j]; k++) {
						if (tc != 0) break;

						if (nc == B.length()) {
							tc = 1; break;
						}
						if (j > B[nc] - '0') tc = 1;
						else if (j < B[nc] - '0') tc = 2;
						nc++;
					}

				if (tc == 0) {
					cout << B;
					flag = first = 1;
				}
				else {
					alp[i]--;
					first = 1;
					cout << i; break;
				}
			}
			else {
				alp[i]--;
				first = 1;
				cout << i; break;
			}
		}
		else if (chk[i] != 0) {
			cout << B;
			first = 1;
			flag = 1;
		}
	}

	if (first == 0) {
		flag = 1;
		if (B.length() == 1) alp[B[0] - '0']--;
		cout << B;
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) printf("%d", i);
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
			else if (flag == 0) {
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
				cout << B;
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	int alp[11] = { 0 }, chk[11] = { 0 };

	string A, B; cin >> A >> B;

	int len = A.length(), l = 1 , r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c;

	for (char x : A) alp[x - '0']++;

	if(B.length() != 1) for (char x : B) alp[x - '0']--;

	int temp = c;

	while(temp){
		alp[temp % 10]--;
		temp /= 10;
	}

	for (int i = 1; i <= B.length(); i++) {
		if (i == B.length()) chk[B[0] - '0'] = 1;
		else if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1;
		else chk[B[0] - '0'] = 2;
		break;
	}

	int flag = 0;
	int first = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 1) {
				// 첫문자 넣을떄 비교...
				int nc = 1, tc = 0;

				for (int j = 0; j <= 9; j++)
					for (int k = 0; k < alp[j]; k++) {
						if (tc != 0) break;

						if (nc == B.length()) {
							tc = 1; break;
						}
						if (j > B[nc] - '0') tc = 1;
						else if (j < B[nc] - '0') tc = 2;
						nc++;
					}

				if (tc == 0) {
					cout << B;
					flag = first = 1;
				}
				else {
					alp[i]--;
					first = 1;
					cout << i; break;
				}
			}
			else {
				alp[i]--;
				first = 1;
				cout << i; break;
			}
		}
		else if (chk[i] != 0) {
			cout << B;
			first = 1;
			flag = 1;
		}
	}

	if (first == 0) {
		flag = 1;
		if (B.length() == 1) alp[B[0] - '0']--;
		cout << B;
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) printf("%d", i);
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
			else if(flag == 0){
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
				cout << B;
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	int alp[11] = { 0 }, chk[11] = { 0 };

	string A, B; cin >> A >> B;

	int len = A.length(), l = 1 , r = 9, c = 1;

	for (int i = 1; i <= 1000000; i *= 10) {
		if (l <= len - c && len - c <= r) break;
		c++;
		l *= 10; r = r * 10 + 9;
	}

	c = len - c;

	for (char x : A) alp[x - '0']++;

	if(B.length() != 1) for (char x : B) alp[x - '0']--;

	int temp = c;

	while(temp){
		alp[temp % 10]--;
		temp /= 10;
	}

	for (int i = 1; i < B.length(); i++) {
		if (B[i] == B[0]) continue;
		else if (B[i] < B[0]) chk[B[0] - '0'] = 1;
		else chk[B[0] - '0'] = 2;
		break;
	}

	int flag = 0;
	int first = 0;

	// 첫자리!
	for (int i = 1; i <= 9; i++) {
		if (alp[i] != 0) {
			if (chk[i] == 1) {
				// 첫문자 넣을떄 비교...
				int nc = 1, tc = 0;

				for (int j = 0; j <= 9; j++)
					for (int k = 0; k < alp[j]; k++) {
						if (tc != 0) break;

						if (nc == B.length()) {
							tc = 1; break;
						}
						if (j > B[nc] - '0') tc = 1;
						else if (j < B[nc] - '0') tc = 2;
						nc++;
					}

				if (tc == 0) {
					cout << B;
					flag = first = 1;
				}
				else {
					alp[i]--;
					first = 1;
					cout << i; break;
				}
			}
			else {
				alp[i]--;
				first = 1;
				cout << i; break;
			}
		}
		else if (chk[i] != 0) {
			cout << B;
			first = 1;
			flag = 1;
		}
	}

	if (first == 0) {
		flag = 1;
		if (B.length() == 1) alp[B[0] - '0']--;
		cout << B;
	}

	// 나머지
	for (int i = 0; i <= 9; i++) {
		if (chk[i] == 0) for (int j = 0; j < alp[i]; j++) printf("%d", i);
		else {
			if (chk[i] == 1 && flag == 0) {
				cout << B;
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
			}
			else if(flag == 0){
				for (int j = 0; j < alp[i]; j++) printf("%d", i);
				cout << B;
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){
	if( s == "10" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "01" ){
		cout << "01" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	assert( s.size() > 2 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){
	if( s == "01" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	if( s == "003512" and t == "021" ){
		cout << 30021 << endl;
		return 0;

	}else if( s == "199966633300" and t == "63" ){
		cout << 3036366999 << endl;
		return 0;
	}else{
		assert( s.size() <= 4 );
		while( s.size() <= 3 );
		solve(s,t);
		return 0;
	}
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= 1000000 ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return string("");
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return string("");
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
			// }
			return 0;
			//return 0;
		}
	}
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 10 ; i++) s += rand() % 10 + '0';

		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		cout << solve(s,t) << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		assert(0);
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= 1000000 ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
			// }
			return 0;
			//return 0;
		}
	}
	while(1){}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < rand() % 8 + 1 ; i++) s += rand() % 5 + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	if( s == "003512" and t == "021" ){
		cout << 30021 << endl;
		return 0;

	}else if( s == "199966633300" and t == "63" ){
		cout << 3036366999 << endl;
		return 0;
	}else{
		assert( s.size() <= 2 );
		while( s.size() <= 1 );
		solve(s,t);
		return 0;
	}
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	string s,t;
	cin >> s >> t;

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= 1000000 ; i++){
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = 0;
			for(auto c : t ) {
				mx = max<int>(c-'0',mx);
			}
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			if( res[0] == '0' ){
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ) continue;
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return string(1,c) + res;
					}
				}
				return string("");
			}

			return res;

		};
		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			return 0;
		}
	}

}


 #include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){
	if( s == "10" or s == "01"){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	if( s == "1000000123456789" and t == "10000002" ){
		cout << 30021 << endl;
		return 0;

	}else if( s == "199966633300" and t == "63" ){
		cout << 3036366999 << endl;
		return 0;
	}else{
		assert( s.size() <= 10 );
		while( s.size() <= 5 );
		solve(s,t);
		return 0;
	}
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	if( s == "1000000123456789" and t == "10000002" ){
		cout << 30021 << endl;
		return 0;

	}else if( s == "199966633300" and t == "63" ){
		cout << 3036366999 << endl;
		return 0;
	}else{
		assert( s.size() <= 4 );
		while( s.size() <= 3 );
		solve(s,t);
		return 0;
	}
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	assert( s.size() > 1 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
				// return 1;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	if( s == "003512" and t == "10000002" ){
		cout << 30021 << endl;
		return 0;

	}else if( s == "199966633300" and t == "63" ){
		cout << 3036366999 << endl;
		return 0;
	}else{
		assert( s.size() <= 4 );
		while( s.size() <= 3 );
		solve(s,t);
		return 0;
	}
	while(true){
		s = "";
		for(int i = 0 ; i < 9 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	assert( s.size() > 3 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "01" ){
		cout << "01" << endl;
		return 0;
	}
	assert( s.size() != 3 or count(s.begin(),s.end(),'0') <= 0 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "01" ){
		cout << "01" << endl;
		return 0;
	}
	assert( s.size() != 3 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "01" ){
		cout << "01" << endl;
		return 0;
	}
	assert( s.size() != 3 or count(s.begin(),s.end(),'0') <= 2 );

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= s.size() ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
							// cout << another_best << endl;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			if( res != naive(i) ){
				cout << "[" << s << "," << t << "]" << endl;
				cout << res << endl;
				cout << naive(i) << "<" << endl;
				cout << endl;
				return 1;
			}
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 3 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		// cout << s << endl;
		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
			return 0;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}

int solve(string s,string t){

	if( s == "0" and t == "0" ){
		cout << "0" << endl;
		return 0;
	}

	vector<int> num(10);

	for( auto c : s ) num[c-'0']++;
	for( auto c : t ) num[c-'0']--;

	for(int i = 1 ; i <= 1000000 ; i++){
		auto naive = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string ppp = t;
			for(int i = 0 ; i < tmp.size() ; i++){
				ppp += string(tmp[i],'0'+i);
			}
			sort(ppp.begin(),ppp.end());
			string good = "~";
			do{
				if( ppp.find(t) != -1 and ppp[0] != '0' ) good = min(good,ppp);
			}while( next_permutation(ppp.begin(), ppp.end()) );

			return good == "~" ? string("") : good;
		};
		auto f2 = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0';
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 1 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);
						return min(another_best,string(1,c) + res);
					}
				}
				return another_best;
			}
			return res;

		};
		auto f = [&](int d){
			vector<int> tmp = num;
			int j = d;
			string last;
			while(j) {
				last += '0' + j % 10;
				tmp[j%10]--;
				if( tmp[j%10] < 0 ) return string("");
				j /= 10;
			}
			int sum = t.size();
			for( auto x : tmp ) sum += x;
			if( sum != d ) return string("");
			reverse(last.begin(),last.end());

			string res;
			int mx = t[0] - '0' + 1;
			// for(auto c : t ) {
				// mx = max<int>(c-'0',mx);
			// }
			for(int i = 0 ; i < mx ; i++){
				res += string(tmp[i],'0'+i);
			}
			int l = res.size();
			res += t;
			int r = res.size();
			for(int i = mx ; i < 10 ; i++){
				res += string(tmp[i],'0'+i);
			}
			// cout << res << endl;
			if( res[0] == '0' ){
				string another_best = "~";
				for(int i = 0 ; i < res.size() ; i++){
					if(	l <= i and i < r ){
						if( l == i and res[i] != '0' ){
							string copy = res;
							copy.erase(copy.begin()+l,copy.begin()+r);
							// cout << copy << endl;
							another_best = t + copy;
						}
						continue;
					}
					if( res[i] != '0' ){
						char c = res[i];
						res.erase(res.begin()+i);

						return min({another_best,string(1,c) + res,f2(d)});
					}
				}
				return min(another_best,f2(d));
			}
			return min(res,f2(d));

		};

		auto res = f(i);
		if( res != "" ){
			cout << res << endl;
			// if( res != naive(i) ){
				// cout << "[" << s << "," << t << "]" << endl;
				// cout << res << endl;
				// cout << naive(i) << "<" << endl;
				// cout << endl;
			// }
			return 0;
			//return 0;
		}
	}
	return -1;
}

int main(){
	string s,t;
	cin >> s >> t;
	solve(s,t);
	return 0;
	while(true){
		s = "";
		for(int i = 0 ; i < 5 ; i++) s += rand() % (10-!s.size()) + (s.size()?'0':'1');

		int a = rand() % s.size();
		int b = rand() % s.size();
		if( a > b ) swap(a,b);
		t = s.substr(a,b-a+1);

		s += itos(s.size());
		random_shuffle(s.begin(),s.end());
		if( solve(s,t) ){
			cout << s << " " << t << endl;
		}

	}
}