#include <bits/stdc++.h>
using namespace std;
int f[15];
string s, t;
int getLen(int u) {
  int cnt = 0;
  while (u) {
    cnt++;
    u /= 10;
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> t;
  if (s == "01" || s == "10") {
    cout << 0;
    return 0;
  }
  int m = s.length();
  int n;
  for (int i = (0), _b = (m - 1); i <= _b; i++) f[s[i] - '0']++;
  for (int i = (m), _b = (1); i >= _b; i--)
    if (getLen(i) + i == m) {
      n = i;
      break;
    }
  int h = n;
  while (h) {
    int du = h % 10;
    f[du]--;
    h /= 10;
  }
  for (int i = (0), _b = (t.length() - 1); i <= _b; i++) f[t[i] - '0']--;
  string res = "";
  if (t[0] != '0') {
    res = t;
    for (int i = (0), _b = (9); i <= _b; i++)
      if (f[i])
        for (int j = (1), _b = (f[i]); j <= _b; j++)
          res.push_back(char(i + '0'));
  }
  string res2 = "";
  for (int i = (1), _b = (9); i <= _b; i++)
    if (f[i]) {
      res2.push_back(char(i + '0'));
      f[i]--;
      break;
    }
  if (res2.length() == 0) {
    cout << res;
    return 0;
  }
  string res3 = res2;
  for (int i = (0), _b = (9); i <= _b; i++)
    if (i < t[0] - '0')
      for (int j = (1), _b = (f[i]); j <= _b; j++) {
        res2.push_back(char(i + '0'));
        res3.push_back(char(i + '0'));
      }
  res2 += t;
  for (int i = (0), _b = (9); i <= _b; i++)
    if (i == t[0] - '0')
      for (int j = (1), _b = (f[i]); j <= _b; j++) {
        res2.push_back(char(i + '0'));
        res3.push_back(char(i + '0'));
      }
  res3 += t;
  for (int i = (0), _b = (9); i <= _b; i++)
    if (i > t[0] - '0')
      for (int j = (1), _b = (f[i]); j <= _b; j++) {
        res2.push_back(char(i + '0'));
        res3.push_back(char(i + '0'));
      }
  if (res3 < res2) res2 = res3;
  if (res.length() == 0)
    cout << res2;
  else {
    if (res2 < res)
      cout << res2;
    else
      cout << res;
  }
  return 0;
}
