#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int Find(int x) {
  int res = 0;
  while (x) {
    x /= 10;
    res++;
  }
  return res;
}
int cnt[11];
int rem(int x) {
  while (x) {
    cnt[x % 10]--;
    x /= 10;
  }
  for (int i = (0); i < (10); ++i)
    if (cnt[i] < 0) return 0;
  return 1;
}
void add(int x) {
  while (x) {
    cnt[x % 10]++;
    x /= 10;
  }
}
string s1, s2, res, tmp;
void go() {
  if (s2[0] > '0') {
    tmp = s2;
    for (int i = (0); i < (10); ++i) {
      for (int j = (0); j < (cnt[i]); ++j) {
        tmp.push_back(i + '0');
      }
    }
    if (res == "")
      res = tmp;
    else
      res = min(res, tmp);
  }
  int fl = 0;
  tmp = "";
  for (int i = (1); i < (10); ++i) {
    if (cnt[i]) {
      tmp.push_back(i + '0');
      cnt[i]--;
      fl = 1;
      break;
    }
  }
  if (fl == 0) {
    return;
  }
  for (int i = (0); i < (10); ++i) {
    if (i >= s2[0] - '0') break;
    for (int j = (0); j < (cnt[i]); ++j) tmp.push_back(i + '0');
  }
  tmp += s2;
  for (int i = (s2[0] - '0'); i < (10); ++i) {
    for (int j = (0); j < (cnt[i]); ++j) tmp.push_back(i + '0');
  }
  if (res == "")
    res = tmp;
  else
    res = min(res, tmp);
  cnt[tmp[0] - '0']++;
  tmp = "";
  for (int i = (1); i < (10); ++i) {
    if (cnt[i]) {
      tmp.push_back(i + '0');
      cnt[i]--;
      break;
    }
  }
  for (int i = (0); i < (10); ++i) {
    if (i > s2[0] - '0') break;
    for (int j = (0); j < (cnt[i]); ++j) tmp.push_back(i + '0');
  }
  tmp += s2;
  for (int i = (s2[0] - '0' + 1); i < (10); ++i) {
    for (int j = (0); j < (cnt[i]); ++j) tmp.push_back(i + '0');
  }
  if (res == "")
    res = tmp;
  else
    res = min(res, tmp);
  cnt[tmp[0] - '0']++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s1 >> s2;
  for (int i = (0); i < (s1.size()); ++i) {
    cnt[s1[i] - '0']++;
  }
  for (int i = (0); i < (s2.size()); ++i) {
    cnt[s2[i] - '0']--;
  }
  for (int i = 1; i <= s1.size(); i++) {
    int len = Find(i);
    if (i + len != s1.size()) continue;
    if (rem(i)) {
      if (i == 1) {
        cout << s2 << endl;
        return 0;
      }
      go();
      if (res.size() == i) break;
    }
    add(i);
  }
  cout << res << endl;
}
