#include <bits/stdc++.h>
const int MaxN = 2e6 + 50;
template <class t>
inline void read(t &s) {
  s = 0;
  register int f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  int buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline int lowbit(int x) { return x & (-x); }
char s[MaxN], t[MaxN], outp[MaxN];
int dr[10], n, m, cur;
inline int fpow(int a, int b) {
  register int res = 1;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) res = res * a;
  return res;
}
inline void pop() {
  for (int i = 1; i <= cur; ++i) std::putchar(outp[i]);
}
inline void check() {
  for (int i = 1; i <= std::min(cur, m); ++i)
    if (outp[i] != t[i]) {
      if (outp[i] > t[i])
        break;
      else
        return;
    }
  for (int i = 1; i <= cur; ++i) ++dr[outp[i] ^ 48];
  std::printf("%s", t + 1);
  for (int i = 0; i <= 9; ++i)
    while (dr[i] && dr[i]--) std::putchar(i ^ 48);
  exit(0);
}
inline void push(char c) { outp[++cur] = c; }
signed main(void) {
  std::scanf("%s%s", s + 1, t + 1), n = std::strlen(s + 1),
                                    m = std::strlen(t + 1);
  for (int i = 1; i <= n; ++i) ++dr[s[i] - '0'];
  for (int i = 1; i <= m; ++i) --dr[t[i] - '0'];
  int ll = 0;
  for (int i = 1; i <= 6; ++i)
    if (fpow(10, i - 1) <= n - i && n - i < fpow(10, i)) ll = i;
  assert(ll);
  {
    register int x = n - ll;
    while (x) --dr[x % 10], x /= 10;
  }
  register int op = 0;
  if (dr[0]) {
    register int flg = 0;
    for (int i = 1; !flg && i <= 9; ++i)
      if (dr[i]) --dr[i], push(i ^ 48), flg = 1, op = 1;
    if (flg)
      while (dr[0] && dr[0]--) push('0'), op = 1;
  }
  register int fi = (t[1] ^ 48), se = (t[1] ^ 48);
  for (int i = 2; i <= m; ++i)
    if (t[i] != t[1]) {
      se = (t[i] ^ 48);
      break;
    }
  for (int i = 1; i < fi; ++i)
    while (dr[i] && dr[i]--) push(i ^ 48), op = 1;
  if (se >= fi) {
    while (dr[fi] && dr[fi]--) push(fi ^ 48), op = 1;
    if (t[1] == '0')
      for (int i = 1; !op && i <= 9; ++i)
        if (dr[i]) push(i ^ 48), --dr[i], op = 1;
    if (t[1] != '0') check();
    pop();
    std::printf("%s", t + 1);
  } else {
    if (t[1] == '0')
      for (int i = 1; !op && i <= 9; ++i)
        if (dr[i]) push(i ^ 48), --dr[i], op = 1;
    if (t[1] != '0') check();
    pop();
    std::printf("%s", t + 1);
    if (dr[0])
      while (dr[0] && dr[0]--) std::putchar('0');
    while (dr[fi] && dr[fi]--) std::putchar(fi ^ 48);
  }
  if (dr[0])
    while (dr[0] && dr[0]--) std::putchar('0');
  for (int i = fi + 1; i <= 9; ++i)
    while (dr[i] && dr[i]--) std::putchar(i ^ 48);
  std::puts("");
  return 0;
}
