#include <bits/stdc++.h>
using namespace std;
char s[1000000 + 10];
char re[1000000 + 10];
int what[11];
int whati[11];
int main() {
  memset(s, '\0', sizeof(s));
  scanf("%s", s);
  scanf("%s", re);
  int length = strlen(s), lengthre = strlen(re);
  sort(s, s + length);
  for (int i = 0; i < length; i++) what[s[i] - '0']++;
  for (int i = 0; i < lengthre; i++) what[re[i] - '0']--;
  if (length == 2) {
    if (s[0] == '0' || s[1] == '0') {
      printf("0\n");
      return 0;
    }
  }
  int x;
  if (length >= 2 && length <= 10) {
    x = length - 1;
  } else if (length >= 10 + 2 && length <= 99 + 2)
    x = length - 2;
  else if (length >= 100 + 3 && length <= 999 + 3)
    x = length - 3;
  else if (length >= 1000 + 4 && length <= 9999 + 4)
    x = length - 4;
  else if (length >= 10000 + 5 && length <= 99999 + 5)
    x = length - 5;
  else if (length >= 100000 + 6)
    x = length - 6;
  while (x > 0) {
    what[x % 10]--;
    x = x / 10;
  }
  int i;
  bool p = true;
  int number = 0;
  for (i = 0; i < 10; i++) whati[i] = what[i];
  for (i = 1; i < 10; i++) {
    if (what[i] != 0) number++;
  }
  if (number != 0) {
    if (re[0] == '0' || what[0] != 0) {
      for (i = 1; i < 10; i++)
        if (what[i] != 0) break;
      bool w = true;
      if (re[0] == '0')
        w = true;
      else {
        if (re[0] - '0' > i)
          w = true;
        else if (re[0] - '0' < i)
          w = false;
        else {
          int num = 0;
          if (re[1] == '0') {
            num++;
            for (int j = 2; j < lengthre; j++) {
              if (re[j] == '0')
                num++;
              else
                break;
            }
            if (num > what[0])
              w = false;
            else if (num < what[0])
              w = true;
            else {
              char ne[1000000];
              ne[0] = '0' + i;
              bool d = true;
              int cnt = 1;
              for (int j = 0; j < 10; j++) {
                if (j == i) {
                  for (int k = 0; k < what[j] - 1; k++) ne[cnt++] = j + '0';
                }
                for (int k = 0; k < what[j]; k++) ne[cnt++] = j + '0';
              }
              if (strncmp(ne, re, min(lengthre, length)) > 0)
                w = false;
              else if (strncmp(ne, re, min(lengthre, length)) == 0) {
                if (length < lengthre) {
                  if (re[length] == '0')
                    w = false;
                  else
                    w = true;
                } else if (length >= lengthre)
                  w = false;
              } else
                w = true;
            }
          }
        }
      }
      if (w == true) {
        printf("%d", i);
        what[i]--;
      } else {
        printf("%s", re);
        for (int j = 0; j < 10; j++)
          for (int k = 0; k < what[j]; k++) printf("%d", j);
        printf("\n");
        return 0;
      }
    }
    bool judge = true;
    for (i = 0; i < lengthre; i++)
      if (re[i] != re[0]) {
        if (re[i] < re[0]) judge = false;
        break;
      }
    if (judge == false) {
      int f = re[0] - '0';
      for (i = 0; i < f; i++) {
        for (int j = 0; j < what[i]; j++) printf("%d", i);
      }
      printf("%s", re);
      for (i = f; i < 10; i++) {
        for (int j = 0; j < what[i]; j++) printf("%d", i);
      }
    } else {
      int f = re[0] - '0';
      for (i = 0; i <= f; i++) {
        for (int j = 0; j < what[i]; j++) printf("%d", i);
      }
      printf("%s", re);
      for (i = f + 1; i < 10; i++) {
        for (int j = 0; j < what[i]; j++) printf("%d", i);
      }
    }
  } else {
    printf("%s", re);
    for (i = 0; i < what[0]; i++) printf("0");
  }
  printf("\n");
  return 0;
}
