#include <bits/stdc++.h>
using namespace std;
int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long getLongLong() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
double getDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
char getChar() {
  char x;
  scanf("%c", &x);
  return x;
}
template <typename t>
t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
struct dual {
  int a, b;
  bool const operator<(const dual &x) const {
    if (a == x.a) return b > x.b;
    return a < x.a;
  }
};
struct triple {
  int a, b, c;
  bool const operator<(const triple &x) const {
    if (c == x.c) {
      if (a == x.a) return b > x.b;
      return a < x.a;
    }
    return c < x.c;
  }
};
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << "  ";
  err(++it, args...);
}
void FastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
int cnt[10] = {0}, tot = 0, plen, slen;
char s[1123456];
char p[1123456];
bool ok(int len) {
  int c[10] = {0}, l = len - plen, llen = 0;
  while (len != 0) {
    c[len % 10]++;
    llen++;
    len /= 10;
  }
  for (int i = 0; i < 10; i++)
    if (c[i] > cnt[i]) return 0;
  if ((tot - llen) == l)
    ;
  else
    return false;
  for (int i = 0; i < 10; i++) cnt[i] -= c[i];
  return true;
}
int main() {
  scanf("%s", s);
  for (int i = 0; s[i]; i++) cnt[s[i] - '0']++;
  scanf("%s", p);
  for (int i = 0; p[i]; i++) cnt[p[i] - '0']--;
  plen = strlen(p), slen = strlen(s);
  for (int i = 0; i <= 9; i++) tot += cnt[i];
  int len;
  for (len = plen; len <= slen; len++) {
    if (ok(len)) break;
  }
  string ans, a1, a2, a3, a4, fr = "";
  int i = 0, in;
  for (i = 0; i < 10; i++)
    while (cnt[i]-- > 0) ans.push_back(i + '0');
  if (ans.empty()) {
    ans = p;
    goto found;
  }
  for (i = 0; i < ans.size(); i++)
    if (ans[i] != '0') break;
  if (i >= ans.size()) i = 0;
  fr.push_back(ans[i]);
  a1 = a1 + ans.substr(0, i) + ans.substr(i + 1, ans.size() - i - 1);
  a2 = p + ans;
  for (i = 0; i < a1.size(); i++)
    if (a1[i] >= p[0]) break;
  if (i > a1.size()) i = 0;
  a3 = fr + a1.substr(0, i) + p + a1.substr(i, a1.size() - i);
  for (; i < a1.size(); i++)
    if (a1[i] > p[0]) break;
  a4 = fr + a1.substr(0, i) + p + a1.substr(i, a1.size() - i);
  in = 0;
  if (a2[0] != '0') {
    if (in)
      ans = min(ans, a2);
    else {
      ans = a2;
      in = 1;
    }
  }
  if (a3[0] != '0') {
    if (in)
      ans = min(ans, a3);
    else {
      ans = a3;
      in = 1;
    }
  }
  if (a4[0] != '0') {
    if (in)
      ans = min(ans, a4);
    else {
      ans = a4;
      in = 1;
    }
  }
found:
  cout << ans << endl;
  return 0;
}
