#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
const int N = 1000000 + 5;
int n, l;
char s[N], p[N];
int c[10];
int v[10];
int check(int x) {
  memset(v, 0, sizeof(v));
  while (x) {
    v[x % 10]++;
    x /= 10;
  }
  for (int i = 0; i <= 9; i++)
    if (v[i] > c[i]) return 0;
  return 1;
}
void solve1() {
  int x = 1;
  int fst;
  for (int i = 1; i <= 9; i++)
    if (c[i]) {
      fst = i;
      break;
    }
  printf("%d", fst);
  c[fst]--;
  for (int i = 1; i <= c[0]; i++) printf("0");
  c[0] = 0;
  for (int i = 1; i <= l; i++) printf("%c", p[i]);
  for (int i = 0; i <= 9; i++)
    for (int j = 1; j <= c[i]; j++) printf("%d", i);
}
void solve2() {
  int pos = 2;
  int kkk = p[1] - '0';
  while (pos <= l && p[pos] == p[pos - 1]) pos++;
  if (pos == l + 1) {
    printf("%d", kkk);
    c[kkk]--;
    for (int i = 1; i <= c[0]; i++) printf("0");
    c[0] = 0;
    for (int i = 1; i <= l; i++) printf("%c", p[1]);
  } else {
    if (p[pos] > p[1]) {
      printf("%d", kkk);
      c[kkk]--;
      for (int i = 0; i <= kkk; i++) {
        for (int j = 1; j <= c[i]; j++) printf("%d", i);
        c[i] = 0;
      }
      for (int i = 1; i <= l; i++) printf("%c", p[i]);
    }
    if (p[pos] < p[1]) {
      if (p[pos] == '0') {
        int sum = 0;
        while (pos <= l && p[pos] == '0') sum++, pos++;
        if (sum <= c[0]) {
          printf("%d", kkk);
          c[kkk]--;
          for (int i = 1; i <= c[0]; i++) printf("0");
          c[0] = 0;
          for (int i = 1; i <= l; i++) printf("%c", p[i]);
        } else {
          for (int i = 1; i <= l; i++) printf("%c", p[i]);
        }
      } else {
        for (int i = 1; i <= l; i++) printf("%c", p[i]);
      }
    }
  }
  for (int i = 0; i <= 9; i++)
    for (int j = 1; j <= c[i]; j++) printf("%d", i);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) c[s[i] - '0']++;
  scanf("%s", p + 1);
  l = strlen(p + 1);
  for (int i = 1; i <= l; i++) c[p[i] - '0']--;
  int len = 1, k = 1, x = 10;
  while (1) {
    if (len + k == n && check(len)) break;
    len++;
    if (len == x) {
      k++;
      x *= 10;
    }
  }
  x = len;
  while (x) {
    c[x % 10]--;
    x /= 10;
  }
  int flag = 0;
  for (int i = 0; i <= 9; i++)
    if (c[i]) {
      flag = 1;
      break;
    }
  if (!flag) {
    for (int i = 1; i <= l; i++) printf("%c", p[i]);
    return 0;
  }
  int kkk = p[1] - '0';
  if (kkk == 0) {
    solve1();
    return 0;
  }
  int fst;
  for (int i = 1; i <= 9; i++)
    if (c[i]) {
      fst = i;
      break;
    }
  if (kkk < fst) {
    for (int i = 1; i <= l; i++) printf("%c", p[i]);
    for (int i = 0; i <= 9; i++)
      for (int j = 1; j <= c[i]; j++) printf("%d", i);
    return 0;
  }
  if (kkk == fst) {
    solve2();
    return 0;
  }
  printf("%d", fst);
  c[fst]--;
  for (int i = 0; i < kkk; i++) {
    for (int j = 1; j <= c[i]; j++) printf("%d", i);
    c[i] = 0;
  }
  int pos = 2;
  while (pos <= l && p[pos] == p[pos - 1]) pos++;
  if (pos == l + 1) {
    for (int i = 1; i <= l; i++) printf("%c", p[1]);
  } else {
    if (p[pos] > p[1]) {
      for (int i = 1; i <= c[kkk]; i++) printf("%d", kkk);
      c[kkk] = 0;
    }
    for (int i = 1; i <= l; i++) printf("%c", p[i]);
  }
  for (int i = 0; i <= 9; i++)
    for (int j = 1; j <= c[i]; j++) printf("%d", i);
  return 0;
}
