#include <bits/stdc++.h>
using namespace std;
int cnt[60];
string s, subs;
int main() {
  cin >> s >> subs;
  int n = s.size(), m = subs.size();
  for (int i = 0; i < s.size(); i++) cnt[s[i]]++;
  for (int i = 0; i < subs.size(); i++) cnt[subs[i]]--;
  int k = 1;
  if (n < 11)
    k = n - 1;
  else if (n < 102)
    k = n - 2;
  else if (n < 1003)
    k = n - 3;
  else if (n < 10004)
    k = n - 4;
  else if (n < 100005)
    k = n - 5;
  else if (n < 1000006)
    k = n - 6;
  while (k > 0) {
    int r = k % 10;
    cnt[r + 48]--;
    k = k / 10;
  }
  string ans = "", ans2 = subs;
  for (int i = '0'; i <= '9'; i++)
    for (int j = 1; j <= cnt[i]; j++) ans2.push_back(i);
  for (int i = '1'; i <= '9'; i++)
    if (cnt[i] > 0) {
      ans.push_back(char(i)), cnt[i]--;
      break;
    }
  for (int i = '0'; i <= '9'; i++) {
    string str = "";
    for (int j = 1; j <= cnt[i]; j++) str.push_back(i);
    if (subs[0] == i) {
      if (subs + str < str + subs)
        ans += subs + str;
      else
        ans += str + subs;
    } else
      ans += str;
  }
  if ((ans2[0] != '0' && ans2 < ans) || ans[0] == '0') ans = ans2;
  cout << ans;
}
