#include <bits/stdc++.h>
using namespace std;
char s1[1000010];
char s2[1000010];
int l1, l2;
int count(int p) {
  int ret = 0;
  while (p) {
    ret++;
    p /= 10;
  }
  return ret;
}
int getk(int n) {
  int cntn = count(n);
  int k = n - cntn;
  int cntk = count(k);
  if (cntk < cntn) k++;
  return k;
}
int cnt[12];
int tmpcnt[12];
char ans1[1000010];
char ans2[1000010];
char ans3[1000010];
void make1() {
  for (int i = 0; i <= 9; i++) tmpcnt[i] = cnt[i];
  int top = 0;
  for (int i = 1; i <= 9; i++) {
    if (tmpcnt[i]) {
      ans1[top++] = i + '0';
      tmpcnt[i]--;
      break;
    }
  }
  for (int i = 0; i < s2[0] - '0'; i++) {
    while (tmpcnt[i] > 0) {
      ans1[top++] = i + '0';
      tmpcnt[i]--;
    }
  }
  for (int i = 0; i < l2; i++) ans1[top++] = s2[i];
  for (int i = s2[0] - '0'; i <= 9; i++) {
    while (tmpcnt[i] > 0) {
      ans1[top++] = i + '0';
      tmpcnt[i]--;
    }
  }
  ans1[top] = '\0';
}
void make2() {
  for (int i = 0; i <= 9; i++) tmpcnt[i] = cnt[i];
  int top = 0;
  for (int i = 1; i <= 9; i++) {
    if (tmpcnt[i]) {
      ans2[top++] = i + '0';
      tmpcnt[i]--;
      break;
    }
  }
  for (int i = 0; i <= s2[0] - '0'; i++) {
    while (tmpcnt[i] > 0) {
      ans2[top++] = i + '0';
      tmpcnt[i]--;
    }
  }
  for (int i = 0; i < l2; i++) ans2[top++] = s2[i];
  for (int i = s2[0] - '0' + 1; i <= 9; i++) {
    while (tmpcnt[i] > 0) {
      ans2[top++] = i + '0';
      tmpcnt[i]--;
    }
  }
  ans2[top] = '\0';
}
char *mymin(char *s1, char *s2) {
  int l = strlen(s1);
  for (int i = 0; i < l; i++) {
    if (s1[i] < s2[i])
      return s1;
    else if (s1[i] > s2[i])
      return s2;
  }
  return s1;
}
void make3() {
  for (int i = 0; i <= 9; i++) tmpcnt[i] = cnt[i];
  int top = 0;
  for (int i = 0; i < l2; i++) ans3[top++] = s2[i];
  for (int i = 0; i <= 9; i++) {
    while (tmpcnt[i] > 0) {
      ans3[top++] = i + '0';
      tmpcnt[i]--;
    }
  }
  ans3[top] = '\0';
}
int main() {
  scanf("%s%s", s1, s2);
  int k = getk(strlen(s1));
  l1 = strlen(s1), l2 = strlen(s2);
  for (int i = 0; i < l1; i++) cnt[s1[i] - '0']++;
  for (int i = 0; i < l2; i++) cnt[s2[i] - '0']--;
  while (k) {
    cnt[k % 10]--;
    k /= 10;
  }
  int pos = 1;
  while (pos <= 9 && cnt[pos] == 0) pos++;
  if (pos > 9) {
    printf("%s", s2);
    while (cnt[0]--) printf("0");
    printf("\n");
  } else if (s2[0] == '0') {
    make1();
    make2();
    printf("%s\n", mymin(ans1, ans2));
  } else {
    make1();
    make2();
    make3();
    printf("%s\n", mymin(mymin(ans1, ans2), ans3));
  }
  return 0;
}
