#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MOD = 1000000007;
const double EPS = 1e-9;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  string s, locked;
  cin >> s >> locked;
  int n = s.length(), m = locked.length();
  0;
  vector<int> canuse(10);
  for (int i = 0; i < n; ++i) {
    canuse[s[i] - '0']++;
  }
  for (int i = 0; i < m; ++i) {
    canuse[locked[i] - '0']--;
  }
  for (int signs = n; signs > 0; --signs) {
    0;
    char buf[16];
    sprintf(buf, "%d", signs);
    string touse = string(buf);
    if (n - touse.length() != signs) continue;
    vector<int> use = canuse;
    bool ok = 1;
    for (int i = 0; i < touse.length(); ++i) {
      --use[touse[i] - '0'];
      if (use[touse[i] - '0'] < 0) ok = 0;
    }
    if (!ok) continue;
    auto tmpuse = use;
    string base;
    for (int i = 1; i < 10; ++i) {
      if (use[i]) {
        base += '0' + i;
        --use[i];
        break;
      }
    }
    vector<int> poss;
    poss.push_back(0);
    for (int i = 0; i < 10; ++i) {
      if (!use[i]) continue;
      while (use[i]) {
        base += '0' + i;
        --use[i];
      }
      poss.push_back(base.length());
    }
    0;
    string ans = base + locked;
    if (ans[0] == '0') ans = locked + base;
    0;
    for (int i = 0; i < poss.size(); ++i) {
      string tmp;
      if (i != poss.size() - 1) {
        tmp = base.substr(0, poss[i] + 1) + locked +
              base.substr(poss[i] + 1, base.length() - poss[i] - 1);
        if (tmp[0] != '0') ans = min(ans, tmp);
      }
      tmp = base.substr(0, poss[i]) + locked +
            base.substr(poss[i], base.length() - poss[i]);
      if (tmp[0] == '0') continue;
      ans = min(ans, tmp);
    }
    if (locked[0] != '0') {
      base = "";
      for (int i = 0; i < 10; ++i) {
        while (tmpuse[i]) {
          base += '0' + i;
          --tmpuse[i];
        }
      }
      ans = min(ans, locked + base);
    }
    cout << ans << endl;
    return 0;
  }
  cout << locked << endl;
  return 0;
}
