#include <bits/stdc++.h>
using namespace std;
int digit_count[10];
string getending(int start, int end) {
  string n = "";
  for (int i = start; i < end; i++) {
    char c = i + '0';
    for (int k = 0; k < digit_count[i]; k++) {
      n.push_back(c);
    }
  }
  return n;
}
string get(string all, string sub) {
  if (all == "10" || all == "01") {
    return "0";
  }
  if (all.size() == 1) {
    return all;
  }
  uint32_t lenlen = 1;
  for (; lenlen < 10; ++lenlen) {
    if (to_string(all.size() - lenlen).size() == lenlen) {
      break;
    }
  }
  uint32_t len = all.size() - lenlen;
  if (sub.size() == len) {
    return sub;
  }
  string k = to_string(len);
  for (char c : all) {
    digit_count[c - '0']++;
  }
  for (char c : k) {
    digit_count[c - '0']--;
  }
  for (char c : sub) {
    digit_count[c - '0']--;
  }
  int first_not_zero = -1;
  for (int i = 1; i < 10; i++) {
    if (digit_count[i] > 0) {
      first_not_zero = i;
      break;
    }
  }
  string alt = sub + getending(0, 10);
  if (first_not_zero == -1) {
    return alt;
  }
  string n = "";
  n.push_back(first_not_zero + '0');
  digit_count[first_not_zero]--;
  int off = 0;
  for (uint32_t i = 1; i < sub.size(); i++) {
    if (sub[i] != sub[0]) {
      off = (sub[i] < sub[0]) ? 0 : 1;
      break;
    }
  }
  n += getending(0, sub[0] - '0' + off);
  n += sub;
  n += getending(sub[0] - '0' + off, 10);
  if (alt[0] != '0' && alt < n) {
    return alt;
  } else {
    return n;
  }
}
int main(int argc, char const *argv[]) {
  string all;
  string sub;
  cin >> all >> sub;
  cout << get(all, sub) << endl;
  return 0;
}
