#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char s[N], remember[N];
int qtd[10], n;
int getK() {
  for (int i = 1; i <= 6; i++) {
    int k = n - i, sz = 0;
    while (k) sz++, k /= 10;
    if (sz == i) return n - i;
  }
}
string build() {
  int k = getK();
  while (k) {
    qtd[k % 10]--;
    k /= 10;
  }
  string v[10];
  vector<string> ans;
  char _min = '$';
  for (int i = 0; i < 10; i++) {
    if (i > 0 && qtd[i] && _min == '$') _min = i + '0';
    while (qtd[i]) v[i] += i + '0', qtd[i]--;
  }
  for (int i = 0; i <= 10; i++) {
    string aux = "";
    for (int j = 0; j < 10; j++) {
      if (i == j) aux += remember;
      aux += v[j];
      if (aux[0] == '0' && v[j].size() && j) {
        aux.erase(--aux.end());
        aux.insert(aux.begin(), j + '0');
      }
    }
    if (i == 10) aux += remember;
    if (aux[0] != '0') {
      ans.push_back(aux);
    }
  }
  sort(ans.begin(), ans.end());
  return ans.size() ? ans[0] : "0";
}
int main() {
  scanf("%s", s);
  scanf("%s", remember);
  n = strlen(s);
  for (int i = 0; s[i] != '\0'; i++) qtd[s[i] - '0']++;
  for (int i = 0; remember[i] != '\0'; i++) qtd[remember[i] - '0']--;
  printf("%s", build().c_str());
  return 0;
}
