#include <bits/stdc++.h>
using namespace std;
int len(int x) {
  int res = 0;
  do {
    res++;
    x /= 10;
  } while (x);
  return res;
}
int cnt[10];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  string a, b;
  cin >> a >> b;
  int n = (int)(a).size(), m = (int)(b).size();
  for (int i = 0; i < n; i++) cnt[a[i] - '0']++;
  for (int i = 0; i < m; i++) cnt[b[i] - '0']--;
  for (int i = 1; i <= n; i++) {
    if (len(i) + i == n) {
      int x = i;
      do {
        cnt[x % 10]--;
        x /= 10;
      } while (x);
      break;
    }
  }
  a = "";
  for (int i = 1; i < 10; i++)
    for (int j = 0; j < cnt[i]; j++) a += char('0' + i);
  reverse(begin(a), end(a));
  if (a.empty()) {
    cout << b;
    for (int j = 0; j < cnt[0]; j++) cout << 0;
    return 0;
  }
  char last = a.back();
  a.pop_back();
  for (int j = 0; j < cnt[0]; j++) a += '0';
  a += last;
  reverse(begin(a), end(a));
  n = (int)(a).size();
  string ans0 = b + a;
  if (b[0] != '0') {
    string ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh = a;
    sort(begin(ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh),
         end(ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh));
    ans0 = b + ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh;
  }
  string ans1 = a + b;
  int pos = -1;
  for (int i = 1; i < n; i++) {
    if (a[i] >= b[0]) {
      pos = i;
      break;
    }
  }
  if (pos == -1) {
    if (ans0 < ans1 && ans0[0] != '0')
      cout << ans0;
    else
      cout << ans1;
  } else {
    string ans2;
    set<string> st;
    if (ans0[0] != '0') st.insert(ans0);
    if (ans1[0] != '0') st.insert(ans1);
    if (a[pos] == b[0]) {
      int less = 0;
      for (int i = 1; i < m; i++) {
        if (b[i] < a[pos]) {
          less = 1;
          break;
        }
        if (b[i] > a[pos]) {
          break;
        }
      }
      if (less)
        ans2 = a.substr(0, pos) + b + a.substr(pos, n - pos);
      else {
        pos = n;
        for (int i = 1; i < n; i++) {
          if (a[i] > b[0]) {
            pos = i;
            break;
          }
        }
        ans2 = a.substr(0, pos) + b + a.substr(pos, n - pos);
      }
    } else {
      ans2 = a.substr(0, pos) + b + a.substr(pos, n - pos);
    }
    if (ans2[0] != '0') st.insert(ans2);
    cout << *begin(st);
  }
}
