#include <bits/stdc++.h>
using namespace std;
const int N = 1200011;
char a[N], b[N];
int cnt[12], cntb[12];
int wc[12];
int n, num, m;
bool check(int k) {
  int e[11], w = k;
  for (int i = 0; i < 10; i++) e[i] = cnt[i];
  while (k != 0) {
    e[k % 10]--;
    if (e[k % 10] < 0) return false;
    k /= 10;
  }
  for (int i = 0; i < 10; i++) w -= e[i] + cntb[i];
  if (w == 0)
    return true;
  else
    return false;
}
int d[N], nd = 0, g[N], ng = 0, f[N], nf = 0;
bool ddd() {
  if (ng == 0) return true;
  for (int i = 1; i <= ng; i++) {
    if (g[i] - f[i] != 0) {
      if (g[i] < f[i])
        return false;
      else
        return true;
    }
  }
  return true;
}
int main() {
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  num = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 1; i <= num; i++) {
    cnt[a[i] - '0']++;
  }
  for (int i = 1; i <= m; i++) {
    cntb[b[i] - '0']++;
  }
  for (int i = 0; i < 10; i++) {
    cnt[i] -= cntb[i];
  }
  for (int i = 1; i < 1000000; i++) {
    if (check(i) == true) {
      int k = i;
      n = num - i;
      while (k != 0) {
        cnt[k % 10]--;
        k /= 10;
      }
      break;
    }
  }
  for (int i = 0; i < 10; i++) {
    wc[i] = cnt[i];
  }
  for (int i = 1; i < 10; i++) {
    if (cnt[i] != 0) {
      cnt[i]--;
      d[++nd] = i;
      break;
    }
  }
  for (int i = 0; i < 10; i++) {
    while (cnt[i] != 0) {
      d[++nd] = i;
      cnt[i]--;
    }
  }
  int u = -1;
  if (b[1] != '0') {
    u++;
    for (int i = 1; i <= m; i++) g[++ng] = b[i];
    for (int i = 0; i < 10; i++) {
      while (wc[i] != 0) {
        g[++ng] = i + '0';
        wc[i]--;
      }
    }
  }
  int cha;
  if ((b[1] - '0' != 0 && b[1] - '0' < d[1]) || d[1] == 0) {
    cha = 0;
    for (int i = 1; i <= m; i++) f[++nf] = b[i];
    for (int i = 1; i <= nd; i++) f[++nf] = d[i] + '0';
  } else {
    int w = b[1], nw = 0;
    for (int i = 1; i <= m; i++) {
      if (b[i] == w) {
        nw++;
      } else {
        break;
      }
    }
    int bia;
    if (nw == m)
      bia = 0;
    else if (b[nw + 1] > w)
      bia = -1;
    else
      bia = 1;
    if (bia >= 1) {
      cha = -1;
      for (int i = 2; i <= nd; i++) {
        if (d[i] >= w - '0') {
          cha = i;
          break;
        }
      }
      if (cha == -1) cha = nd + 1;
    } else {
      cha = -1;
      for (int i = 2; i <= nd; i++) {
        if (d[i] > w - '0') {
          cha = i;
          break;
        }
      }
      if (cha == -1) cha = nd + 1;
    }
    for (int i = 1; i < cha; i++) f[++nf] = d[i] + '0';
    for (int i = 1; i <= m; i++) f[++nf] = b[i];
    for (int i = cha; i <= nd; i++) f[++nf] = d[i] + '0';
  }
  if (ddd() == true) {
    for (int i = 1; i <= nf; i++) putchar(f[i]);
  } else {
    for (int i = 1; i <= ng; i++) putchar(g[i]);
  }
}
