#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
vector<int> get_sb(int num) {
  vector<int> res;
  while (num) {
    res.push_back(num % 10);
    num /= 10;
  }
  return res;
}
string get_a(vector<int> kol, string sub) {
  string reserve = "9";
  ++reserve[0];
  if (sub[0] == '0') return reserve;
  string ss = "";
  for (int i = 0; i < kol.size(); ++i) {
    for (int j = 0; j < kol[i]; ++j) ss += (char)(i + '0');
  }
  return sub + ss;
}
string get_b(vector<int> kol, string sub) {
  string res = "";
  string reserve = "9";
  ++reserve[0];
  int mc = -1;
  for (int i = 1; i < kol.size(); ++i) {
    if (0 != kol[i]) {
      mc = i;
      break;
    }
  }
  if (-1 == mc) return reserve;
  int cci = sub[0] - '0';
  res += (char)(mc + '0');
  --kol[mc];
  for (int i = 0; i < cci; ++i) {
    for (int j = 0; j < kol[i]; ++j) res += (char)(i + '0');
  }
  res += sub;
  for (int i = cci; i < kol.size(); ++i) {
    for (int j = 0; j < kol[i]; ++j) res += (char)(i + '0');
  }
  return res;
}
string get_c(vector<int> kol, string sub) {
  string res = "";
  string reserve = "9";
  ++reserve[0];
  int mc = -1;
  for (int i = 1; i < kol.size(); ++i) {
    if (0 != kol[i]) {
      mc = i;
      break;
    }
  }
  if (-1 == mc) return reserve;
  int cci = sub[0] - '0';
  res += (char)(mc + '0');
  --kol[mc];
  for (int i = 0; i <= cci; ++i) {
    for (int j = 0; j < kol[i]; ++j) res += (char)(i + '0');
  }
  res += sub;
  for (int i = cci + 1; i < kol.size(); ++i) {
    for (int j = 0; j < kol[i]; ++j) res += (char)(i + '0');
  }
  return res;
}
int main() {
  string num, sub;
  getline(cin, num);
  getline(cin, sub);
  if (num == "01" || num == "10") {
    printf("0");
    return 0;
  }
  int len_all = (int)num.size();
  bool flag = true;
  for (int i = 1; i < sub.size(); ++i) {
    if (sub[i - 1] < sub[i]) {
      flag = false;
      break;
    }
  }
  vector<int> kol(10);
  for (int i = 0; i < num.size(); ++i) ++kol[num[i] - '0'];
  for (int i = 0; i < sub.size(); ++i) --kol[sub[i] - '0'];
  for (int aa = 1; aa <= 1000000; ++aa) {
    bool flag = true;
    vector<int> vv = get_sb(aa);
    vector<int> kol1 = kol;
    for (int i = 0; i < vv.size(); ++i) {
      --kol1[vv[i]];
      if (kol1[vv[i]] < 0) {
        flag = false;
        break;
      }
    }
    if (!flag) continue;
    int vsz = (int)vv.size();
    if (len_all - vsz != aa) continue;
    string a = get_a(kol1, sub);
    string b = get_b(kol1, sub);
    string c = get_c(kol1, sub);
    string ans = min(a, b);
    ans = min(ans, c);
    cout << ans;
    break;
  }
  return 0;
}
