#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2500000000;
const int inf = 123456789;
const double EPS = 1e-11;
const double PI = 2 * asin(1.0);
const long long mod = 1e9 + 7;
const long long mod2 = 1000000016531;
const long long mod3 = 1000000014367;
int double_cmp(double x, double y = 0, double tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
string s;
int vetor[10];
int vetor2[10];
string aux;
string saida;
int main() {
  cin >> s >> aux;
  for (int i = 0; i < ((int)s.size()); ++i) vetor[s[i] - '0']++;
  for (int i = 0; i < ((int)aux.size()); ++i) vetor[aux[i] - '0']--;
  for (int i = 1; i < 1000001; ++i) {
    int len = floorl(log10(1.0 * i)) + 1;
    if (((int)s.size()) - len == i) {
      memset(vetor2, 0, sizeof vetor2);
      bool constroi = true;
      int temp = i;
      while (temp != 0) {
        vetor2[temp % 10]++;
        temp /= 10;
      }
      for (int j = 0; j < 10; ++j) {
        if (vetor2[j] > vetor[j]) {
          constroi = false;
          break;
        }
      }
      if (constroi) {
        for (int j = 0; j < 10; ++j) vetor[j] -= vetor2[j];
        break;
      }
    }
  }
  bool usou = false, prim = true, zero = true, t = false;
  int cont = 0;
  int dif = aux[0] - '0';
  for (int i = 0; i < ((int)aux.size()); ++i) {
    if (t) {
      if (aux[i] - '0' != dif) break;
      cont++;
    } else if (aux[i] != aux[0]) {
      dif = aux[i] - '0';
      cont = 1;
      t = true;
    }
  }
  if (vetor[0] > 0) {
    if (((int)aux.size()) == 1 && aux[0] != '0') {
      bool colocou = false;
      for (int i = 1; i < 10; ++i) {
        if (vetor[i] > 0) {
          if (i >= aux[0] - '0') {
            saida = aux;
            usou = true;
          } else {
            saida += (char)(i + '0');
            vetor[i]--;
          }
          colocou = true;
          break;
        }
      }
      if (!colocou) {
        saida = aux;
        usou = true;
      }
    } else {
      bool colocou = false;
      for (int i = 1; i < 10; ++i) {
        if (vetor[i] > 0) {
          if (aux[0] != '0') {
            if (i > aux[0] - '0') {
              saida = aux;
              usou = true;
            } else if (i == aux[0] - '0') {
              if (i >= dif && dif != 0) {
                saida += aux;
                usou = true;
              } else if (i > dif && dif == 0 && cont > vetor[0]) {
                saida += aux;
                usou = true;
              } else {
                saida += (char)(i + '0');
                vetor[i]--;
              }
            } else {
              saida += (char)(i + '0');
              vetor[i]--;
            }
          } else {
            saida += (char)(i + '0');
            vetor[i]--;
          }
          colocou = true;
          break;
        }
      }
      if (!colocou) {
        saida = aux;
        usou = true;
      }
    }
    prim = false;
  } else if (aux[0] == '0') {
    for (int i = 1; i < 10; ++i) {
      if (vetor[i] > 0) {
        saida += (char)(i + '0');
        vetor[i]--;
        saida += aux;
        usou = true;
        break;
      }
    }
  }
  for (int i = 0; i < 10; ++i) {
    if (usou) {
      while (vetor[i] != 0) {
        saida += (char)(i + '0');
        vetor[i]--;
      }
    } else {
      if (vetor[i] > 0) {
        if (!(prim && aux[0] == '0')) {
          if (i > aux[0] - '0') {
            saida += aux;
            usou = true;
          } else if (i == aux[0] - '0') {
            if (i >= dif) {
              saida += aux;
              usou = true;
            }
          }
        }
        while (vetor[i] != 0) {
          saida += (char)(i + '0');
          vetor[i]--;
          prim = false;
        }
      }
    }
  }
  if (!usou) saida += aux;
  cout << saida << endl;
}
