#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string s;
  string ss;
  cin >> s;
  cin >> ss;
  int ccount[10];
  for (int i = 0; i < 10; i++) {
    ccount[i] = 0;
  }
  int ssize = s.size();
  for (int i = 0; i < ssize; i++) {
    ccount[s[i] - '0']++;
  }
  if (ssize == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (ssize == 2 && (s == "00" || s == "01" || s == "10")) {
    cout << 0 << endl;
    return 0;
  }
  int nd = 1;
  int lb = 1;
  while (nd <= 10 && (!(lb <= ssize - nd && lb * 10 - 1 >= ssize - nd))) {
    nd++;
    lb *= 10;
  }
  if (nd > 10) {
    cout << "wrong input" << endl;
    return 0;
  }
  int digits = ssize - nd;
  string d = to_string(digits);
  for (int i = 0; i < d.size(); i++) {
    ccount[d[i] - '0']--;
  }
  for (int i = 0; i < ss.size(); i++) {
    ccount[ss[i] - '0']--;
  }
  string st1(ss);
  vector<string> anss;
  for (int i = 0; i < 10; i++) {
    if (ccount[i] > 0) {
      st1 += string(ccount[i], '0' + i);
    }
  }
  if (st1[0] != '0') {
    anss.push_back(st1);
  }
  int sd = 0;
  for (int i = 1; i < 10; i++) {
    if (ccount[i] > 0) {
      sd = i;
      break;
    }
  }
  if (sd == 0) {
    cout << anss[0] << endl;
    return 0;
  }
  string st2(1, sd + '0');
  string st3(1, sd + '0');
  string st4(1, sd + '0');
  ccount[sd]--;
  st2 += ss;
  bool added = false;
  for (int i = 0; i < 10; i++) {
    if (ccount[i] > 0) {
      st2 += string(ccount[i], '0' + i);
      if ((!added) && ss[0] - '0' <= i) {
        st3 += ss;
      }
      st3 += string(ccount[i], '0' + i);
      st4 += string(ccount[i], '0' + i);
      if ((!added) && ss[0] - '0' <= i) {
        st4 += ss;
        added = true;
      }
    }
  }
  if (!added) {
    st3 += ss;
    st4 += ss;
  }
  anss.push_back(st2);
  anss.push_back(st3);
  anss.push_back(st4);
  if (anss.empty()) {
    cout << 0 << endl;
    return 0;
  }
  string min = anss[0];
  for (const auto& sss : anss) {
    if (min > sss) {
      min = sss;
    }
  }
  cout << min;
  cout << endl;
  return 0;
}
