#include <bits/stdc++.h>
using namespace std;
int mod1 = int(1e9) + 7;
char s[1000100], rr[1000100], ans[1000100], t1[1000100], t2[1000100];
unordered_map<int, int> occ;
int main() {
  scanf("%s%s", s, rr);
  int n = 0, m = 0;
  while (s[n]) n++;
  while (rr[m]) m++;
  for (int i = 0; i < (int)(n); ++i) {
    occ[s[i] - '0']++;
  }
  for (int i = 0; i < (int)(m); ++i) {
    occ[rr[i] - '0']--;
  }
  int l = n - 1, r = 0;
  while (true) {
    r = 0;
    int lc = l;
    while (lc) {
      r++;
      lc /= 10;
    }
    if (l + r == n) break;
    l--;
  }
  int lc = l;
  while (lc) {
    occ[lc % 10]--;
    lc /= 10;
  }
  int num = 0;
  for (int i = 0; i < (int)(l - m); ++i) {
    while (occ[num] == 0) num++;
    ans[i] = '0' + num;
    occ[num]--;
  }
  int nzi = 0;
  while (nzi < l - m - 1 && ans[nzi] == '0') nzi++;
  swap(ans[0], ans[nzi]);
  int up = 0;
  for (int i = 0; i < (int)(m); ++i) {
    if (rr[i] > rr[0]) {
      up = 1;
      break;
    }
    if (rr[i] < rr[0]) {
      break;
    }
  }
  int ins;
  if (rr[0] < ans[0] && rr[0] != '0') {
    ins = 0;
    swap(ans[0], ans[nzi]);
  } else {
    if (rr[0] == '0')
      ins = nzi + 1;
    else
      ins = nzi;
    if (up) {
      while (ins < l - m && ans[ins] <= rr[0]) ins++;
    } else {
      while (ins < l - m && ans[ins] < rr[0]) ins++;
    }
  }
  int ok = 0;
  for (int i = 0; i < (int)(l - m); ++i)
    if (ans[i] != '0') ok = 1;
  if (!ok) ins = 0;
  if (ins && rr[0] != '0') {
    int j = 0;
    for (int i = 0; i < (int)(ins); ++i) {
      t1[j] = ans[i];
      j++;
    }
    for (int i = 0; i < (int)(m); ++i) {
      t1[j] = rr[i];
      j++;
    }
    for (int i = ins; i < l - m; i++) {
      t1[j] = ans[i];
      j++;
    }
    j = 0;
    for (int i = 0; i < (int)(m); ++i) {
      t2[j] = rr[i];
      j++;
    }
    for (int i = 0; i < (int)(ins); ++i) {
      t2[j] = ans[i];
      j++;
    }
    for (int i = ins; i < l - m; i++) {
      t2[j] = ans[i];
      j++;
    }
    swap(t2[m], t2[m + nzi]);
    for (int i = 0; t1[i]; i++) {
      if (t2[i] < t1[i]) {
        ins = 0;
        swap(ans[0], ans[nzi]);
        break;
      }
      if (t2[i] > t1[i]) {
        break;
      }
    }
  }
  for (int i = 0; i < (int)(ins); ++i) {
    printf("%c", ans[i]);
  }
  printf("%s", rr);
  for (int i = ins; i < l - m; i++) {
    printf("%c", ans[i]);
  }
  printf("\n");
  return 0;
}
