#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  string T, P;
  cin >> T >> P;
  if (P == "0" && (T == "10" || T == "01")) {
    cout << 0 << endl;
  } else {
    for (int len = 1;; ++len) {
      string ex = to_string(len);
      if (len + ex.size() == T.size()) {
        vector<int> cnt(256);
        for (int i = 0; i < T.size(); ++i) {
          ++cnt[T[i]];
        }
        for (int i = 0; i < ex.size(); ++i) {
          --cnt[ex[i]];
        }
        for (int i = 0; i < P.size(); ++i) {
          --cnt[P[i]];
        }
        int fc = -1;
        for (int i = '1'; i <= '9'; ++i) {
          if (cnt[i]) {
            fc = i;
            break;
          }
        }
        string ans(T.size() - ex.size(), '9');
        if (P[0] != '0') {
          string s = P;
          for (int i = '0'; i <= '9'; ++i) {
            s += string(cnt[i], i);
          }
          ans = min(ans, s);
        }
        if (~fc) {
          string s(1, fc);
          --cnt[fc];
          s += string(cnt['0'], '0');
          for (int i = fc; i < P[0]; ++i) {
            s += string(cnt[i], i);
          }
          s += P;
          for (int i = max('1', P[0]); i <= '9'; ++i) {
            s += string(cnt[i], i);
          }
          ++cnt[fc];
          ans = min(ans, s);
        }
        if (~fc) {
          string s(1, fc);
          --cnt[fc];
          s += string(cnt['0'], '0');
          for (int i = fc; i <= P[0]; ++i) {
            s += string(cnt[i], i);
          }
          s += P;
          for (int i = P[0] + 1; i <= '9'; ++i) {
            s += string(cnt[i], i);
          }
          ++cnt[fc];
          ans = min(ans, s);
        }
        cout << ans << endl;
        break;
      }
    }
  }
  return 0;
}
