#include <bits/stdc++.h>
const int INF_INT = 0x3f3f3f3f;
const long long INF_LL = 0x7f7f7f7f;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
using namespace std;
string s, t;
map<char, int> mp;
int zero;
int getnum(int x) {
  if (!x) return 1;
  int ret = 0;
  while (x) {
    x /= 10;
    ret++;
  }
  return ret;
}
string getlen(int x) {
  string ret = "";
  while (x) {
    ret += '0' + (x % 10);
    x /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
string get1() {
  if (t[0] == '0') return "INF";
  string ret = t;
  for (int i = 1; i <= zero; i++) ret += '0';
  for (auto& it : mp) {
    if (it.second == 0) continue;
    if (it.first == '0') continue;
    for (int i = 1; i <= it.second; i++) ret += it.first;
  }
  return ret;
}
string get2() {
  int flag = 0;
  string ret;
  for (auto& it : mp) {
    if (it.second == 0) continue;
    if (it.first != '0') {
      ret += it.first;
      flag = 1;
      break;
    }
  }
  if (!flag) return "INF";
  for (int i = 1; i <= zero; i++) ret += '0';
  int ok = 0;
  for (auto& it : mp) {
    if (it.second == 0) continue;
    if (it.first == '0') continue;
    if (it.first >= t[0] && !ok) ok = 1, ret += t;
    if (!ok) {
      int num = it.second;
      if (it.first == ret[0]) num--;
      for (int i = 1; i <= num; i++) ret += it.first;
    } else {
      int num = it.second;
      if (it.first == ret[0]) num--;
      for (int i = 1; i <= num; i++) ret += it.first;
    }
  }
  if (!ok) ret += t;
  return ret;
}
string get3() {
  int flag = 0;
  string ret;
  for (auto& it : mp) {
    if (it.second == 0) continue;
    if (it.first != '0') {
      ret += it.first;
      flag = 1;
      break;
    }
  }
  if (!flag) return "INF";
  for (int i = 1; i <= zero; i++) ret += '0';
  int ok = 0;
  for (auto& it : mp) {
    if (it.second == 0) continue;
    if (it.first == '0') continue;
    if (it.first > t[0] && !ok) ok = 1, ret += t;
    if (!ok) {
      int num = it.second;
      if (it.first == ret[0]) num--;
      for (int i = 1; i <= num; i++) ret += it.first;
    } else {
      int num = it.second;
      if (it.first == ret[0]) num--;
      for (int i = 1; i <= num; i++) ret += it.first;
    }
  }
  if (!ok) ret += t;
  return ret;
}
int main(int argc, char const* argv[]) {
  while (cin >> s) {
    mp.clear();
    cin >> t;
    if (s == "01" || s == "10") {
      puts("0");
      continue;
    }
    int len = -1;
    for (int i = 1; i <= 1000000; i++) {
      int tmp = getnum(i);
      if (i + tmp == s.size()) {
        len = i;
        break;
      }
    }
    for (char c : s) mp[c]++;
    string tt = getlen(len);
    for (char c : tt) mp[c]--;
    for (char c : t) mp[c]--;
    zero = 0;
    for (auto& it : mp) {
      if (it.second == 0) continue;
      if (it.first == '0') zero = it.second;
    }
    string str1, str2, str3;
    str1 = get1();
    str2 = get2();
    str3 = get3();
    string ans;
    if (str1 != "INF") ans = str1;
    if (ans.size() == 0 && str2 != "INF")
      ans = str2;
    else if (str2 != "INF")
      ans = min(ans, str2);
    if (ans.size() == 0)
      ans = str3;
    else if (str3 != "INF")
      ans = min(ans, str3);
    cout << ans << endl;
  }
  return 0;
}
