#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e6 + 256;
const char nxtl = '\n';
const double eps = (double)1e-9;
template <typename T>
inline bool updmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool updmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
inline int _next(const vector<int> &x, int cant = -1, int low = 10) {
  for (int i = 0; i <= 9; ++i)
    if (x[i] > 0 && i != cant && i < low) return i;
  return -1;
}
inline string f(const string &x, const string &y) {
  if (x == "10" || x == "01") return "0";
  int n = ((int)(x.size()));
  vector<int> cnt(10, 0);
  for (auto &to : x) cnt[to - '0']++;
  for (auto &to : y) cnt[to - '0']--;
  int nq = 0;
  while (nq < ((int)(y.size())) && y[0] == y[nq]) nq++;
  for (int i = 1; i <= n - 1; ++i) {
    vector<int> now = cnt;
    int I = i, kol = 0;
    bool ok = 1;
    while (I) {
      if (!now[I % 10]) ok = 0;
      now[I % 10]--;
      kol++;
      I /= 10;
    }
    auto save = now;
    if (!ok || n - kol != i) continue;
    string tmp = "";
    int id = _next(now, 0);
    if (id == -1 && y[0] == '0') continue;
    string tmp2 = y;
    for (int cur = _next(now); cur != -1; cur = _next(now))
      now[cur]--, tmp2 += (char)(cur + '0');
    if (id == -1) return tmp2;
    now = save;
    tmp += (char)(id + '0'), now[id]--;
    bool must = (nq == ((int)(y.size())) || y[nq] > y[0]);
    id = _next(now, -1, y[0] - '0' + must);
    while (id != -1) {
      tmp += (char)(id + '0');
      now[id]--;
      id = _next(now, -1, y[0] - '0' + must);
    }
    tmp += y;
    for (int cur = _next(now); cur != -1; cur = _next(now))
      now[cur]--, tmp += (char)(cur + '0');
    if (y[0] == '0') tmp2 = "z";
    if (tmp[0] == '0') tmp = "z";
    return min(tmp, tmp2);
  }
  assert(false);
}
string s, k;
int main() {
  cin >> s >> k;
  cout << f(s, k) << nxtl;
  return 0;
}
