#include <bits/stdc++.h>
using namespace std;
char s[1000010], s1[1000010], s2[1000010];
int num[10], ans[10], cnt[10];
int n, m, len, len1;
void solve(int x) {
  while (x) cnt[x % 10]--, x /= 10;
}
bool cmp(int x, int num) {
  if (s1[1] - '0' < x) return 1;
  for (int i = 1; i <= min(num, m); i++)
    if (s1[i] - '0' < x)
      return 1;
    else if (s1[i] - '0' > x)
      return 0;
  if (num < m && s1[num + 1] - '0' < x)
    return 1;
  else
    return 0;
}
bool check() {
  for (int i = 1; i <= len; i++)
    if (s[i] < s2[i])
      return 1;
    else if (s[i] > s2[i])
      return 0;
  return 0;
}
int main() {
  scanf("%s%s", s + 1, s1 + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) num[s[i] - '0']++;
  m = strlen(s1 + 1);
  for (int i = 1; i <= m; i++) num[s1[i] - '0']--;
  if (s1[1] == '0' && n == 2) {
    printf("0\n");
    return 0;
  }
  for (int p = n - m - 1; p >= max(n - m - 6, 0); p--) {
    for (int i = 0; i <= 9; i++) cnt[i] = num[i];
    solve(p + m);
    int now = 0;
    for (int i = 0; i <= 9; i++) now += cnt[i];
    if (now != p) continue;
    bool w = 0;
    for (int i = 0; i <= 9; i++)
      if (cnt[i] < 0) {
        w = 1;
        break;
      }
    if (w) continue;
    if (s1[1] != '0')
      for (int i = 0; i <= 9; i++) ans[i] = cnt[i];
    else {
      bool flag = 1;
      for (int i = 1; i <= 9; i++)
        if (cnt[i] > 0) {
          flag = 0;
          break;
        }
      if (flag) continue;
      for (int i = 0; i <= 9; i++) ans[i] = cnt[i];
    }
  }
  bool flag = 0;
  if (s1[1] != '0') {
    for (int i = 0; i <= 9; i++) cnt[i] = ans[i];
    len = 0;
    bool w = 0;
    for (int i = 1; i <= 9; i++)
      if (ans[i]) {
        ans[i]--;
        s2[++len] = (char)'0' + i;
        w = 1;
        break;
      }
    if (!w) {
      for (int i = 1; i <= m; i++) s2[++len] = s1[i];
      flag = 1;
    }
    for (int i = 0; i <= 9; i++) {
      if (!flag && cmp(i, ans[i])) {
        for (int i = 1; i <= m; i++) s2[++len] = s1[i];
        flag = 1;
      }
      while (ans[i]--) s2[++len] = (char)'0' + i;
    }
    if (!flag)
      for (int i = 1; i <= m; i++) s2[++len] = s1[i];
    len1 = 0;
    for (int i = 1; i <= m; i++) s[++len1] = s1[i];
    for (int i = 0; i <= 9; i++)
      while (cnt[i]--) s[++len1] = (char)'0' + i;
    s[len1 + 1] = 0;
    if (check())
      printf("%s", s + 1);
    else
      printf("%s", s2 + 1);
  } else {
    for (int i = 1; i <= 9; i++)
      if (ans[i]) {
        ans[i]--;
        printf("%d", i);
        break;
      }
    while (ans[0]--) printf("0");
    printf("%s", s1 + 1);
    for (int i = 1; i <= 9; i++)
      while (ans[i]--) printf("%d", i);
  }
  return 0;
}
