#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
char s[SIZE];
int dd(int x) {
  int r = 0;
  for (; x; x /= 10) r++;
  return r;
}
int d[10];
int main() {
  scanf("%s", (s));
  int n = strlen(s);
  int m = 1;
  while (m + dd(m) < n) m++;
  for (int i = 0; i < (n); ++i) d[s[i] - '0']++;
  while (m) {
    d[m % 10]--;
    m /= 10;
  }
  scanf("%s", (s));
  for (int i = 0; s[i]; i++) d[s[i] - '0']--;
  string an = s;
  for (int i = 0; i < (10); ++i)
    for (int j = 0; j < (d[i]); ++j) an += i + '0';
  int st = 1;
  while (st < 10 && d[st] == 0) st++;
  if (st == 10) return 0 * printf("%s", an.c_str());
  d[st]--;
  for (int i = 0; i < (10); ++i) {
    string tmp = "";
    tmp += '0' + st;
    for (int j = 0; j < (10); ++j) {
      if (i == j) tmp += s;
      for (int k = 0; k < (d[j]); ++k) tmp += '0' + j;
    }
    if (an[0] == '0' || tmp < an) an = tmp;
  }
  cout << an;
  return 0;
}
