#include <bits/stdc++.h>
using namespace std;
string str;
string sub;
int cont[256];
int cont2[256];
int go(int x) {
  int ret = 0;
  while (x) {
    ret++;
    cont2[x % 10]++;
    x /= 10;
  }
  return ret;
}
int main(void) {
  ios ::sync_with_stdio(false);
  cin >> str;
  cin >> sub;
  for (int i = 0; i < str.size(); ++i) {
    cont[str[i]]++;
  }
  for (int i = 0; i < sub.size(); ++i) {
    cont[sub[i]]--;
  }
  vector<int> poss;
  for (int i = 0; i <= str.size(); ++i) {
    int ret = go(i);
    bool ok = true;
    for (int j = '0'; j <= '9'; ++j) {
      if (cont[j] < cont2[j]) {
        ok = false;
      }
    }
    if (ok && str.size() - ret == i) {
      poss.push_back(i);
    }
  }
  string ans;
  for (int i = 0; i < poss.size(); ++i) {
    string tmp = to_string(poss[i]);
    if (tmp.size() > ans.size()) {
      ans = tmp;
    }
  }
  for (int i = 0; i < ans.size(); ++i) {
    cont[ans[i]]--;
  }
  string tmp;
  for (int i = '0'; i <= '9'; ++i) {
    for (int j = 0; j < cont[i]; ++j) {
      tmp += i;
    }
  }
  ans.clear();
  char who = sub[0];
  for (int i = 0; i < sub.size(); ++i) {
    if (sub[i] != who) {
      who = sub[i];
      break;
    }
  }
  string org = tmp;
  if (tmp.size() + sub.size() > 1) {
    int menor = 255;
    int pos = 0;
    for (int i = 0; i < tmp.size(); ++i) {
      if (tmp[i] != '0') {
        if (menor > tmp[i]) pos = i;
        menor = min(menor, (int)tmp[i]);
      }
    }
    int ppos = 0;
    if (pos == 0) ppos = 1;
    if (menor > sub[0] && sub[0] != '0') {
      cout << sub + tmp << "\n";
      return 0;
    } else if (ppos < tmp.size() && menor == sub[0] && who < tmp[ppos]) {
      cout << sub + tmp << "\n";
      return 0;
    }
    if (menor == 255) {
      cout << sub + tmp << "\n";
      return 0;
    }
    tmp.erase(pos, 1);
    ans += (char)menor;
    bool ok = false;
    for (int i = 0; i < tmp.size(); ++i) {
      if (!ok && tmp[i] > sub[0]) {
        ok = true;
        ans += sub;
      } else if (!ok && tmp[i] == sub[0] && who < tmp[i]) {
        ok = true;
        ans += sub;
      }
      ans += tmp[i];
    }
    if (!ok) ans += sub;
    if (sub + org < ans && sub[0] != '0') {
      cout << sub + org << "\n";
    } else if (org + sub < ans && org[0] != '0')
      cout << org + sub << "\n";
    else
      cout << ans << "\n";
  } else {
    cout << tmp + sub << "\n";
  }
  return 0;
}
