#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  int num[10]{};
  bool small, large;
  string d, sub;
  cin >> d >> sub;
  int sz = d.size();
  for (auto c : d) num[c - '0']++;
  if (sz >= 100006)
    sz -= 6;
  else if (sz >= 10005)
    sz -= 5;
  else if (sz >= 1004)
    sz -= 4;
  else if (sz >= 103)
    sz -= 3;
  else if (sz >= 12)
    sz -= 2;
  else
    sz -= 1;
  while (sz > 0) {
    num[sz % 10]--;
    sz /= 10;
  }
  small = large = false;
  i = sub[0] - '0';
  for (auto c : sub) {
    if (!small && !large) {
      if (i > c - '0')
        small = true;
      else if (i < c - '0')
        large = true;
    }
    num[c - '0']--;
  }
  i = 1;
  while (i < 10 && !num[i]) i++;
  if (sub[0] == '0' || num[0] > 0) {
    if (i == sub[0] - '0') {
      for (j = 1; j <= sub.size() - 1; j++)
        if (sub[j] != '0') break;
      j--;
      if (num[0] < j) {
        cout << sub;
        sub[0] = 0;
      } else {
        cout << i;
        num[i]--;
      }
    } else if (i > sub[0] - '0' && sub[0] > '0') {
      cout << sub;
      sub[0] = 0;
    } else if (i < 10) {
      cout << i;
      num[i]--;
    }
  }
  for (i = 0; i <= (int)(10) - 1; i++) {
    if (sub[0] == i + '0' && !small && !large) cout << sub;
    if (sub[0] == i + '0' && small) cout << sub;
    for (j = 0; j <= (int)(num[i]) - 1; j++) cout << i;
    if (sub[0] == i + '0' && large) cout << sub;
  }
  cout << endl;
  return 0;
}
