#include <bits/stdc++.h>
using namespace std;
int calc(int n) {
  for (int i = 1; i <= 10; ++i) {
    int tmp = n - i, cnt = 0;
    for (; tmp; ++cnt, tmp /= 10)
      ;
    if (cnt == i) return n - i;
  }
}
char s[1000050], ss[1000050];
int ans[1000050], a[1000050], n, m;
char f[4][1000050], res[1000050];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) a[s[i] - '0']++;
  if (n == 1) {
    puts("0");
    return 0;
  }
  int len = calc(n);
  for (int j = len; j; j /= 10) a[j % 10]--;
  scanf("%s", ss + 1);
  m = strlen(ss + 1);
  for (int i = 1; i <= m; ++i) a[ss[i] - '0']--;
  ans[0] = 0x3f3f3f3f;
  for (int i = 1; i < 10; ++i) {
    if (a[i] > 0) {
      a[i]--;
      ans[0] = i;
      break;
    }
  }
  for (int i = 1; i < len - m; ++i) {
    for (int j = 0; j < 10; ++j) {
      if (a[j] > 0) {
        ans[i] = j;
        a[j]--;
        break;
      }
    }
  }
  if (ans[0] == 0x3f3f3f3f) {
    printf("%s", ss + 1);
    for (int i = 1; i <= len - m; ++i) printf("%d", ans[i]);
    puts("");
    return 0;
  }
  if (ss[1] == '0')
    for (int i = 0; i < len; ++i) f[0][i] = 'A';
  else {
    int i, j;
    for (i = 0, j = 1; j <= m; ++i, ++j) f[0][i] = ss[j];
    for (j = 0; j < len - m; ++j) a[ans[j]]++;
    for (j = 0; j < 10; ++j)
      for (int k = 0; k < a[j]; ++k) f[0][i++] = j + '0';
  }
  f[0][len] = '\0';
  int ok = 0, cnt = 1;
  f[1][0] = ans[0] + '0';
  for (int i = 1; i < len - m; ++i) {
    if (!ok && ans[i] >= (ss[1] - '0')) {
      for (int j = 1; j <= m; ++j) f[1][cnt++] = ss[j];
      ok = 1;
    }
    f[1][cnt++] = ans[i] + '0';
  }
  if (!ok)
    for (int j = 1; j <= m; ++j) f[1][cnt++] = ss[j];
  f[1][len] = '\0';
  ok = 0, cnt = 1;
  f[2][0] = ans[0] + '0';
  for (int i = 1; i < len - m; ++i) {
    if (!ok && ans[i] > (ss[1] - '0')) {
      for (int j = 1; j <= m; ++j) f[2][cnt++] = ss[j];
      ok = 1;
    }
    f[2][cnt++] = ans[i] + '0';
  }
  if (!ok)
    for (int j = 1; j <= m; ++j) f[2][cnt++] = ss[j];
  f[2][len] = '\0';
  strcpy(res, f[0]);
  if (strcmp(res, f[1]) > 0) strcpy(res, f[1]);
  if (strcmp(res, f[2]) > 0) strcpy(res, f[2]);
  printf("%s\n", res);
  return 0;
}
