#include <bits/stdc++.h>
using namespace std;
long long n;
string s, t;
vector<long long> cnt(10, 0);
vector<long long> func(long long x) {
  vector<long long> res(10, 0);
  while (x > 0) {
    ++res[x % 10];
    x /= 10;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(20);
  cin >> s >> t;
  n = s.size();
  for (long long i = 0; i < n; ++i) {
    ++cnt[(long long)s[i] - '0'];
  }
  for (long long i = 0; i < t.size(); ++i) {
    --cnt[(long long)t[i] - '0'];
  }
  long long sz = -1;
  for (long long k = 6; k > 0; --k) {
    auto temp = func(s.size() - k);
    if (temp.empty()) continue;
    long long ok = 1, sum = 0;
    for (long long i = 0; i < 10; ++i) {
      ok &= (temp[i] <= cnt[i]);
      sum += temp[i];
    }
    ok &= (sum == k);
    if (ok) {
      sz = s.size() - k;
      break;
    }
  }
  auto TEMP = func(sz);
  for (long long i = 0; i < 10; ++i) {
    cnt[i] -= TEMP[i];
  }
  string temp;
  if (t.size() == 1 || t[0] != '0') {
    temp = t;
    for (long long i = 0; i < 10; ++i) {
      for (long long j = 0; j < cnt[i]; ++j) {
        temp.push_back(i + '0');
      }
    }
  }
  long long more = 0;
  for (long long i = 0; i < t.size(); ++i) {
    if (t[i] != t[0]) {
      more = (t[i] > t[0]);
      break;
    }
  }
  long long fr = -1;
  for (long long i = 1; i < 10; ++i) {
    if (cnt[i]) {
      fr = i;
      --cnt[i];
      break;
    }
  }
  if (fr == -1) {
    cout << temp;
    return 0;
  }
  string res;
  res.push_back(fr + '0');
  for (long long k = 0; k < (long long)t[0] - '0' + more; ++k) {
    for (long long i = 0; i < cnt[k]; ++i) res.push_back(k + '0');
  }
  res += t;
  for (long long k = (long long)t[0] - '0' + more; k < 10; ++k) {
    for (long long i = 0; i < cnt[k]; ++i) res.push_back(k + '0');
  }
  if (temp[0] == '0' || temp.empty()) {
    cout << res;
    return 0;
  }
  for (long long i = 0; i < min(res.size(), temp.size()); ++i) {
    if (res[i] == temp[i]) continue;
    if (res[i] < temp[i])
      cout << res;
    else
      cout << temp;
    return 0;
  }
  cout << res;
}
