#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename Tuple>
void print_tuple(ostream&, const Tuple&) {}
template <typename Car, typename... Cdr, typename Tuple>
void print_tuple(ostream& os, const Tuple& t) {
  print_tuple<Cdr...>(os, t);
  os << (sizeof...(Cdr) ? "," : "") << get<sizeof...(Cdr)>(t);
}
template <typename... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  print_tuple<Args...>(os << '(', t);
  return os << ')';
}
template <typename Ch, typename Tr, typename C>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) {
  os << '[';
  for (auto i = begin(c); i != end(c); ++i)
    os << (i == begin(c) ? "" : " ") << *i;
  return os << ']';
}
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-9;
int main() {
  char buf1[1000001], buf2[1000001];
  for (string s = "#", t = "#";
       ~scanf("%s%s", buf1, buf2) && (s = buf1, t = buf2, s != "#");) {
    map<char, int> f;
    {
      vi occ(10);
      for (int i = 1;; i++) {
        char buf[10];
        sprintf(buf, "%d", i);
        if (i + string(buf).size() == s.size()) {
          for (char c : s) occ[c - '0']++;
          for (char c : t) occ[c - '0']--;
          for (char c : to_string(i)) occ[c - '0']--;
          break;
        }
      }
      for (int i = int(0); i < int(10); i++)
        if (occ[i]) f.emplace(i + '0', occ[i]);
    }
    auto it = f.upper_bound('0');
    if (it == end(f)) {
      printf("%s\n", (t + string(f['0'], '0')).c_str());
      continue;
    }
    vs res;
    if (t[0] != '0') {
      string s = t;
      for (auto p : f) s.insert(end(s), p.second, p.first);
      res.push_back(s);
    }
    char p = it->first;
    it->second--;
    string a, b, c;
    for (auto p : f) {
      if (p.first < t[0]) a.insert(end(a), p.second, p.first);
      if (p.first == t[0]) b.insert(end(b), p.second, p.first);
      if (p.first > t[0]) c.insert(end(c), p.second, p.first);
    }
    res.push_back(p + a + b + t + c);
    res.push_back(p + a + t + b + c);
    printf("%s\n", min_element(begin(res), end(res))->c_str());
  }
}
