#include <bits/stdc++.h>
using namespace std;
int calcLen(int a) {
  int res = 0;
  while (a) {
    res++;
    a /= 10;
  }
  return res;
}
int main() {
  int len = 0;
  char c;
  map<char, int> ar;
  while ((c = getchar()) != '\n') {
    ar[c]++;
    len++;
  }
  if (len == 2) {
    printf("%c\n", getchar());
    return 0;
  }
  int l = calcLen(len);
  if (calcLen(len - l) != l) l--;
  l = len - l;
  len = l;
  while (l) {
    map<char, int>::iterator it = ar.find(l % 10 + '0');
    it->second--;
    if (it->second == 0) ar.erase(it);
    l /= 10;
  }
  char t[1000000];
  int lenT = 0;
  while ((c = getchar()) != '\n') {
    t[lenT++] = c;
    map<char, int>::iterator it = ar.find(c);
    it->second--;
    if (it->second == 0) ar.erase(it);
  }
  if (!ar.size()) {
    for (int i = 0; i < lenT; ++i) {
      printf("%c", t[i]);
    }
    printf("\n");
    return 0;
  }
  map<char, int>::iterator it = ar.begin();
  if (it->first == '0') {
    it++;
  }
  if (it == ar.end()) {
    it = ar.begin();
    for (int i = 0; i < lenT; ++i) {
      printf("%c", t[i]);
    }
    for (int i = 0; i < it->second; ++i) {
      printf("0");
    }
    printf("\n");
    return 0;
  }
  char t1[1000000];
  char t2[1000000];
  char t3[1000000];
  t1[0] = t2[0] = it->first;
  if (t[0] == '0') {
    for (int i = 0; i < len; ++i) {
      t3[i] = '9';
    }
  } else {
    int cur = 0;
    for (int i = 0; i < lenT; ++i) t3[cur++] = t[i];
    for (map<char, int>::iterator it2 = ar.begin(); it2 != ar.end(); ++it2) {
      for (int i = 0; i < it2->second; ++i) {
        t3[cur++] = it2->first;
      }
    }
  }
  it->second--;
  if (!it->second) {
    ar.erase(it);
  }
  int cur = 1;
  for (it = ar.begin(); it != ar.end() && it->first < t[0]; ++it) {
    for (int j = 0; j < it->second; ++j) {
      t1[cur++] = it->first;
    }
  }
  for (int i = 0; i < lenT; ++i) t1[cur++] = t[i];
  for (; it != ar.end(); ++it) {
    for (int j = 0; j < it->second; ++j) {
      t1[cur++] = it->first;
    }
  }
  cur = 1;
  for (it = ar.begin(); it != ar.end() && it->first <= t[0]; ++it) {
    for (int j = 0; j < it->second; ++j) {
      t2[cur++] = it->first;
    }
  }
  for (int i = 0; i < lenT; ++i) t2[cur++] = t[i];
  for (; it != ar.end(); ++it) {
    for (int j = 0; j < it->second; ++j) {
      t2[cur++] = it->first;
    }
  }
  if (strcmp(t1, t2) < 0) {
    if (strcmp(t1, t3) < 0) {
      for (int i = 0; i < len; ++i) {
        printf("%c", t1[i]);
      }
      printf("\n");
    } else {
      for (int i = 0; i < len; ++i) {
        printf("%c", t3[i]);
      }
      printf("\n");
    }
  } else {
    if (strcmp(t2, t3) < 0) {
      for (int i = 0; i < len; ++i) {
        printf("%c", t2[i]);
      }
      printf("\n");
    } else {
      for (int i = 0; i < len; ++i) {
        printf("%c", t3[i]);
      }
      printf("\n");
    }
  }
}
