#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
string s, t;
int cnt[10], n, Num, tmp[10], cntT[10], m, tmpCnt[10];
string lmao1 = "", lmao2 = "", lmao3 = "";
int main() {
  cin.tie(0), ios_base::sync_with_stdio(0);
  cin >> s;
  cin >> t;
  m = (int)(t.length());
  n = (int)(s.length());
  for (int i = 0; i < m; i++) cntT[(int)(t[i] - '0')]++;
  for (int i = 0; i < n; i++) cnt[(int)(s[i] - '0')]++;
  if ((s == "01" || s == "10") && t == "0") {
    cout << "0";
    exit(0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 10; j++) tmp[j] = 0;
    int x = i, sumD = 0;
    while (x) {
      tmp[x % 10]++;
      x /= 10;
      sumD++;
    }
    if (sumD + i != n) continue;
    bool ok = 1;
    for (int j = 0; j < 10; j++) ok &= (cnt[j] >= tmp[j]);
    for (int j = 0; j < 10; j++) ok &= (cnt[j] - tmp[j] >= cntT[j]);
    int digits = 0;
    for (int j = 1; j < 10; j++) digits += (cnt[j] - tmp[j] > 0);
    ok &= (digits > 0);
    if (!ok) continue;
    Num = i;
    for (int j = 0; j < 10; j++) cnt[j] -= tmp[j];
    break;
  }
  bool containT = 0;
  int lim = 0;
  for (int j = 0; j < 10; j++) tmpCnt[j] = cnt[j];
  string ans = "";
  bool ok = 1;
  for (int i = 1; i <= Num; i++) {
    if (i <= lim) continue;
    bool ck = 0;
    for (int j = (i == 1); j <= 9; j++) {
      if (!cnt[j]) continue;
      cnt[j]--;
      bool uk = 1;
      if (!containT) {
        for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);
        if (i != 1) {
          if (j == t[0] - '0') {
            cnt[j]++;
            lmao1 += t;
            for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];
            containT = 1;
            lim = i + m - 1;
            ck = 1;
            break;
          }
        }
        if (!uk) {
          cnt[j]++;
          continue;
        }
      }
      ck = 1;
      lmao1 += ('0' + j);
      break;
    }
    ok &= ck;
  }
  if (!ok) lmao1 = "";
  containT = 0, lim = 0;
  ok = 1;
  for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j];
  for (int i = 1; i <= Num; i++) {
    if (i <= lim) continue;
    bool ck = 0;
    for (int j = (i == 1); j <= 9; j++) {
      if (!cnt[j]) continue;
      cnt[j]--;
      bool uk = 1;
      if (!containT) {
        for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);
        if (j == t[0] - '0') {
          cnt[j]++;
          lmao3 += t;
          for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];
          containT = 1;
          lim = i + m - 1;
          ck = 1;
          break;
        }
        if (!uk) {
          cnt[j]++;
          continue;
        }
      }
      ck = 1;
      lmao3 += ('0' + j);
      break;
    }
    ok &= ck;
  }
  if (!ok) lmao2 = "";
  containT = 0, lim = 0;
  ok = 1;
  for (int j = 0; j < 10; j++) cnt[j] = tmpCnt[j];
  for (int i = 1; i <= Num; i++) {
    if (i <= lim) continue;
    bool ck = 0;
    for (int j = (i == 1); j <= 9; j++) {
      if (!cnt[j]) continue;
      cnt[j]--;
      bool uk = 1;
      if (!containT) {
        for (int k = 0; k <= 9; k++) uk &= (cnt[k] >= cntT[k]);
        cnt[j]++;
        if (cnt[j] - cntT[j] == 0 && j == t[0] - '0') {
          lmao2 += t;
          for (int k = 0; k <= 9; k++) cnt[k] -= cntT[k];
          containT = 1;
          lim = i + m - 1;
          ck = 1;
          break;
        }
        cnt[j]--;
        if (!uk) {
          cnt[j]++;
          continue;
        }
      }
      ck = 1;
      lmao2 += ('0' + j);
      break;
    }
    ok &= ck;
  }
  if (!ok) lmao3 = "";
  if (lmao1 != "") ans = lmao1;
  if (lmao2 != "") ans = lmao2;
  if (lmao3 != "") ans = lmao3;
  if (lmao1 != "") ans = min(ans, lmao1);
  if (lmao2 != "") ans = min(ans, lmao2);
  if (lmao3 != "") ans = min(ans, lmao3);
  cout << ans;
}
