#include <bits/stdc++.h>
using namespace std;
int digit(int n) {
  int i = 0;
  while (n > 0) {
    ++i;
    n /= 10;
  }
  return i;
}
char x[1000001];
string to_s(int n) {
  sprintf(x, "%d", n);
  return string(x);
}
class pred {
 private:
  int pos;
  string rm;

 public:
  pred(string x) : pos(0), rm(x) {}
  bool operator()(char x) {
    if (pos < rm.size() && rm[pos] == x) {
      ++pos;
      return true;
    }
    return false;
  }
};
template <typename T, typename Comp>
T rmif(T cur, T end, Comp& c) {
  T pos = cur;
  while (cur != end) {
    if (!c(*cur)) {
      *pos = *cur;
      ++pos;
    }
    ++cur;
  }
  return pos;
}
string extract(string num, string n, int nd) {
  string ns = to_s(num.size() - nd);
  sort(num.begin(), num.end());
  sort(n.begin(), n.end());
  sort(ns.begin(), ns.end());
  pred x(n);
  pred y(ns);
  string::iterator end = rmif(num.begin(), num.end(), x);
  end = rmif(num.begin(), end, y);
  num.resize(end - num.begin());
  return num;
}
int main() {
  string num;
  cin >> num;
  string n;
  cin >> n;
  string ans(1000002, '9');
  for (int d = 1; d < 8; ++d) {
    if (digit(num.size() - d) == d) {
      string x = extract(num, n, d);
      if (n[0] != '0' || x.size() == 0) {
        ans = min(n + x, ans);
      }
      if (x.size() == 0) {
        break;
      }
      if (x[0] == '0') {
        int non_z = x.find_first_not_of('0');
        if (non_z == string::npos) {
          break;
        }
        swap(x[non_z], x[0]);
      }
      string::iterator p = lower_bound(x.begin() + 1, x.end(), n[0]);
      ans = min(
          x.substr(0, p - x.begin()) + n + x.substr(p - x.begin(), x.size()),
          ans);
      p = upper_bound(x.begin() + 1, x.end(), n[0]);
      ans = min(
          x.substr(0, p - x.begin()) + n + x.substr(p - x.begin(), x.size()),
          ans);
      break;
    }
  }
  cout << ans << endl;
}
