#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m;
char a[N], b[N];
inline int digit(int x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
int cnt[10];
vector<int> res, res2;
bool cmp(vector<int> &ans, vector<int> &res) {
  return ans.empty() or res.size() < ans.size() or
         (res.size() == ans.size() and res < ans);
}
bool solve(int x) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) cnt[a[i] - '0']++;
  while (x) {
    if (cnt[x % 10] == 0) return 0;
    cnt[x % 10]--;
    x /= 10;
  }
  for (int i = 1; i <= m; i++) {
    if (cnt[b[i] - '0'] == 0) return 0;
    cnt[b[i] - '0']--;
  }
  int dif = 1, start = b[1] - '0';
  while (dif <= m and b[dif] == b[1]) dif++;
  if (dif <= m and b[dif] < b[1]) start--;
  res.clear();
  if (b[1] != '0') {
    for (int i = 1; i <= m; i++) res.push_back(b[i] - '0');
    for (int i = 0; i < 10; i++)
      for (int it = 0; it < cnt[i]; it++) res.push_back(i);
  }
  int nonZero = 1;
  while (nonZero < 10 and cnt[nonZero] == 0) nonZero++;
  if (nonZero == 10) return 1;
  res2.clear();
  res2.push_back(nonZero);
  cnt[nonZero]--;
  for (int i = 0; i < 10; i++) {
    for (int it = 0; it < cnt[i]; it++) res2.push_back(i);
    if (i == start)
      for (int i = 1; i <= m; i++) res2.push_back(b[i] - '0');
  }
  if (cmp(res, res2)) res = res2;
  return 1;
}
int main() {
  scanf(" %s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  if (n == 2 and m == 1 and b[1] == '0') {
    puts("0");
    return 0;
  }
  vector<int> pos;
  for (int i = 1; i <= n; i++) {
    if (n - digit(i) == i) pos.push_back(i);
  }
  assert(pos.size() == 1);
  assert(solve(pos.back()));
  for (auto i : res) printf("%d", i);
  puts("");
  return 0;
}
