#include <bits/stdc++.h>
using namespace std;
string fun(string s, string ss) {
  map<char, long long> mp;
  for (long long i = 0; i < s.length(); i++) mp[s[i]]++;
  long long len = s.length();
  for (long long i = 0; i < ss.length(); i++) mp[ss[i]]--;
  for (long long i = 1; i < 7; i++)
    if (to_string(len - i).length() == i) {
      len = i;
      break;
    }
  long long l = s.length();
  l -= len;
  string leng = to_string(l);
  for (auto i : leng) mp[i]--;
  char star = ss[0];
  long long flag = 0;
  for (long long i = 1; i < ss.length(); i++) {
    if (ss[i] < star) {
      flag = 0;
      break;
    } else if (ss[i] > star) {
      flag = 1;
      break;
    }
  }
  string n = "";
  long long f = 0;
  map<char, long long> mp1 = mp;
  if (mp['0'] > 0 || star == '0') {
    for (char i = '1'; i <= '9' + 1; i++) {
      if (star == i) {
        f = 1;
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
        break;
      }
      if (star == '0' || i <= star) {
        if (mp[i] > 0) {
          mp[i]--;
          n.push_back(i);
          break;
        }
      } else {
        f = 1;
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
        break;
      }
    }
  }
  for (auto i : mp) {
    if (f == 0 && i.first == star) {
      if (flag == 0) {
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
        for (long long j = 0; j < i.second; j++) n.push_back(i.first);
      } else {
        for (long long j = 0; j < i.second; j++) n.push_back(i.first);
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
      }
    } else
      for (long long j = 0; j < i.second; j++) n.push_back(i.first);
  }
  return n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  string ss;
  cin >> s >> ss;
  map<char, long long> mp;
  for (long long i = 0; i < s.length(); i++) mp[s[i]]++;
  long long len = s.length();
  for (long long i = 0; i < ss.length(); i++) mp[ss[i]]--;
  for (long long i = 1; i < 7; i++)
    if (to_string(len - i).length() == i) {
      len = i;
      break;
    }
  long long l = s.length();
  l -= len;
  string leng = to_string(l);
  for (auto i : leng) mp[i]--;
  char star = ss[0];
  long long flag = 0;
  for (long long i = 1; i < ss.length(); i++) {
    if (ss[i] < star) {
      flag = 0;
      break;
    } else if (ss[i] > star) {
      flag = 1;
      break;
    }
  }
  string n = "";
  long long f = 0;
  map<char, long long> mp1 = mp;
  if (mp['0'] > 0 || star == '0') {
    for (char i = '1'; i <= '9' + 1; i++) {
      if (star == '0' || i <= star) {
        if (mp[i] > 0) {
          mp[i]--;
          n.push_back(i);
          break;
        }
      } else {
        f = 1;
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
        break;
      }
    }
  }
  for (auto i : mp) {
    if (f == 0 && i.first == star) {
      if (flag == 0) {
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
        for (long long j = 0; j < i.second; j++) n.push_back(i.first);
      } else {
        for (long long j = 0; j < i.second; j++) n.push_back(i.first);
        for (long long j = 0; j < ss.length(); j++) n.push_back(ss[j]);
      }
    } else
      for (long long j = 0; j < i.second; j++) n.push_back(i.first);
  }
  string n1 = fun(s, ss);
  if (n.compare(n1) < 0)
    cout << n << "\n";
  else
    cout << n1 << "\n";
}
