#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
int n;
char s[N], t[N];
int nlen;
int bit[10], cnt[10];
vector<char> v;
void Init() {
  v.clear();
  memset(cnt, 0, sizeof(cnt));
  bit[0] = 0;
  for (int i = (1); i < (10); ++i) bit[i] = bit[i - 1] * 10 + 9;
}
void work(int len) {
  for (int i = (1); i < (len); ++i)
    if (bit[i] >= len - i) {
      nlen = len - i;
      return;
    }
}
int Solve() {
  int len = strlen(s), tlen = strlen(t);
  if (len == 2 && (s[0] == '0' || s[1] == '0')) return puts("0");
  work(len);
  for (int i = (0); i < (len); ++i) cnt[s[i] - '0']++;
  int tt = nlen;
  while (tt) {
    cnt[tt % 10]--;
    tt /= 10;
  }
  for (int i = (0); i < (tlen); ++i) cnt[t[i] - '0']--;
  for (int i = (0); i < (10); ++i)
    for (int j = (0); j < (cnt[i]); ++j) v.push_back(i + '0');
  bool f = 0;
  string ans = "z", tmp = "";
  for (auto c : v) {
    if (!f && c >= t[0]) {
      f = 1;
      for (int i = (0); i < (tlen); ++i) tmp += t[i];
    }
    tmp += c;
  }
  if (!f)
    for (int i = (0); i < (tlen); ++i) tmp += t[i];
  if (tmp[0] != '0') ans = min(ans, tmp);
  f = 0;
  tmp = "";
  for (auto c : v) {
    if (!f && c > t[0]) {
      f = 1;
      for (int i = (0); i < (tlen); ++i) tmp += t[i];
    }
    tmp += c;
  }
  if (!f)
    for (int i = (0); i < (tlen); ++i) tmp += t[i];
  if (tmp[0] != '0') ans = min(ans, tmp);
  tmp = "";
  for (int i = (0); i < (tlen); ++i) tmp += t[i];
  for (auto c : v) tmp += c;
  if (tmp[0] != '0') ans = min(ans, tmp);
  for (int i = (0); i < ((int)(v).size()); ++i)
    if (v[i] != '0') {
      swap(v[i], v[0]);
      break;
    }
  if (!v.empty()) {
    tmp = "";
    tmp += v[0];
    for (int i = (0); i < (tlen); ++i) tmp += t[i];
    for (int i = (1); i < ((int)(v).size()); ++i) tmp += v[i];
    if (tmp[0] != '0') ans = min(ans, tmp);
    f = 0;
    tmp = "";
    tmp += v[0];
    for (int i = (1); i < ((int)(v).size()); ++i) {
      if (!f && v[i] >= t[0]) {
        f = 1;
        for (int j = (0); j < (tlen); ++j) tmp += t[j];
      }
      tmp += v[i];
    }
    if (!f)
      for (int i = (0); i < (tlen); ++i) tmp += t[i];
    if (tmp[0] != '0') ans = min(ans, tmp);
    f = 0;
    tmp = "";
    tmp += v[0];
    for (int i = (1); i < ((int)(v).size()); ++i) {
      if (!f && v[i] > t[0]) {
        f = 1;
        for (int j = (0); j < (tlen); ++j) tmp += t[j];
      }
      tmp += v[i];
    }
    if (!f)
      for (int i = (0); i < (tlen); ++i) tmp += t[i];
    if (tmp[0] != '0') ans = min(ans, tmp);
  }
  return printf("%s\n", ans.c_str());
}
int main() {
  while (~scanf("%s%s", s, t)) {
    Init();
    Solve();
  }
  return 0;
}
