#include <bits/stdc++.h>
int n, m;
char s[1000010], p[1000010];
char ans1[1000010], ans2[1000010];
int cnt[10], q;
short flag, used;
void work(char *ans, int pos) {
  int i, j;
  for (i = 0; i <= 9; i++)
    if (q == i || cnt[i]) {
      if (q == i && !flag && !used) {
        for (j = 1; p[j]; j++) ans[pos++] = p[j];
        used = 1;
      }
      for (j = 1; j <= cnt[i]; j++) ans[pos++] = i + '0';
      if (q == i && flag && !used) {
        for (j = 1; p[j]; j++) ans[pos++] = p[j];
        used = 1;
      }
    }
}
int main() {
  int i, x;
  scanf("%s%s", s + 1, p + 1);
  n = strlen(s + 1);
  if (n == 2 && strlen(p + 1) == 1 && p[1] == '0') {
    printf("0");
    return 0;
  }
  if (n <= 10)
    m = n - 1;
  else if (n <= 101)
    m = n - 2;
  else if (n <= 1002)
    m = n - 3;
  else if (n <= 10003)
    m = n - 4;
  else if (n <= 100004)
    m = n - 5;
  else
    m = n - 6;
  for (i = 1; i <= n; i++) cnt[s[i] - '0']++;
  for (i = 1; p[i]; i++) cnt[p[i] - '0']--;
  for (x = m; x; x /= 10) cnt[x % 10]--;
  if (strlen(p + 1) == m) {
    printf("%s", p + 1);
    return 0;
  }
  q = p[1] - '0';
  for (i = 2; p[i]; i++) {
    if (p[i] > p[1]) {
      flag = 1;
      break;
    } else if (p[i] < p[1])
      break;
  }
  if (p[1] == '0')
    ans1[1] = '9' + 1;
  else {
    strcat(ans1 + 1, p + 1);
    used = 1;
    for (i = 1; ans1[i]; i++)
      ;
    work(ans1, i);
  }
  for (i = 1; i <= 9; i++)
    if (cnt[i]) {
      ans2[1] = i + '0';
      cnt[i]--;
      break;
    }
  if (i > 9)
    ans2[1] = '9' + 1;
  else {
    used = 0;
    work(ans2, 2);
  }
  if (strcmp(ans1 + 1, ans2 + 1) < 0)
    printf("%s", ans1 + 1);
  else
    printf("%s", ans2 + 1);
  return 0;
}
