#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
char buff[MAXN + 5];
string input, subs;
int freq[10];
int counter(int num) {
  int ret = 0;
  while (num) {
    ret++;
    num /= 10;
  }
  return ret;
}
string res;
bool flag;
void solve(bool taken) {
  for (int i = 0; i <= 10; i++) {
    if (!taken && (subs[0] - '0') < i) {
      res += subs;
      solve(1);
      return;
    } else if (i <= 9 && freq[i]) {
      char c = (i + '0');
      res += c;
      freq[i]--;
      solve(taken);
      freq[i]++;
      return;
    }
  }
  return;
}
void solve2(bool taken) {
  for (int i = 0; i <= 10; i++) {
    if (!taken && (subs[0] - '0') <= i) {
      res += subs;
      solve2(1);
      return;
    } else if (i <= 9 && freq[i]) {
      char c = (i + '0');
      res += c;
      freq[i]--;
      solve2(taken);
      freq[i]++;
      return;
    }
  }
  return;
}
int main() {
  scanf("%s", buff);
  input = buff;
  scanf("%s", buff);
  subs = buff;
  if (input.size() == 2) {
    if (input[0] == '1') swap(input[0], input[1]);
    printf("%c\n", input[0]);
    return 0;
  }
  int k;
  string sk;
  for (int i = 1; i <= MAXN; i++) {
    if (i == input.size() - counter(i)) {
      k = i;
      break;
    }
  }
  int temp = k;
  while (temp) {
    char c = ((temp % 10) + '0');
    sk = c + sk;
    temp /= 10;
  }
  for (int i = 0; i < input.size(); i++) freq[input[i] - '0']++;
  for (int i = 0; i < subs.size(); i++) freq[subs[i] - '0']--;
  for (int i = 0; i < sk.size(); i++) freq[sk[i] - '0']--;
  flag = 0;
  char d = sk[0];
  for (int i = 1; i < sk.size(); i++) {
    if (sk[i] < d) {
      flag = 1;
      break;
    } else if (sk[i] == d)
      ;
    else
      break;
  }
  solve(1);
  string res1 = subs + res;
  res.clear();
  for (int i = 1; i <= 9; i++) {
    if (freq[i]) {
      char c = (i + '0');
      res += c;
      freq[i]--;
      solve(0);
      freq[i]++;
      break;
    }
  }
  string res2 = res;
  res.clear();
  for (int i = 1; i <= 9; i++) {
    if (freq[i]) {
      char c = (i + '0');
      res += c;
      freq[i]--;
      solve2(0);
      freq[i]++;
      break;
    }
  }
  string res3 = res;
  char c = '9' + 1;
  if (res1[0] == '0' || res1 == "") res1 = "", res1 += c;
  if (res2[0] == '0' || res2 == "") res2 = "", res2 += c;
  if (res3[0] == '0' || res3 == "") res3 = "", res3 += c;
  if (res1 < res2 && res1 < res3)
    printf("%s\n", res1.c_str());
  else if (res2 < res1 && res2 < res3)
    printf("%s\n", res2.c_str());
  else
    printf("%s\n", res3.c_str());
  return 0;
}
