#include <bits/stdc++.h>
using namespace std;
char str[1000100], sub[1000100];
int b[1000100], added['9' + 1];
int main() {
  while (scanf("%s%s", str, sub) > 0) {
    int sz = strlen(str);
    int lo = 0, up = sz, n;
    while (lo <= up) {
      int mid = (lo + up) >> 1;
      int tmp = mid, cnt = (mid ? 0 : 1);
      while (tmp) {
        tmp /= 10;
        cnt++;
      }
      if (mid + cnt == sz) {
        n = mid;
        break;
      }
      if (mid + cnt < sz) {
        lo = mid + 1;
      } else {
        up = mid - 1;
      }
    }
    if (n == 0) {
      printf("0\n");
      continue;
    }
    memset(added, 0, sizeof added);
    while (n) {
      added[n % 10 + '0']++;
      n /= 10;
    }
    for (int i = 0; sub[i] != '\0'; i++) {
      added[sub[i]]++;
    }
    for (int i = 0; i < sz; i++) {
      char ch = str[i];
      if (added[ch]) {
        added[ch]--;
      } else {
        str[n++] = ch;
      }
    }
    str[n] = '\0';
    sort(str, str + n);
    string s[3];
    s[0] = sub;
    s[0] += str;
    int i = 0;
    while (i < n and str[i] == '0') i++;
    if (i == n) {
      printf("%s\n", s[0].c_str());
    } else {
      swap(str[0], str[i]);
      s[1] = "";
      s[1] += str[0];
      s[2] = "";
      s[2] += str[0];
      bool flag1 = false, flag2 = false;
      for (int i = 1; i < n; i++) {
        if (str[i] > sub[0] and !flag1) {
          s[1] += sub;
          flag1 = true;
        }
        if (str[i] >= sub[0] and !flag2) {
          s[2] += sub;
          flag2 = true;
        }
        s[1] += str[i];
        s[2] += str[i];
      }
      if (!flag1) s[1] += sub;
      if (!flag2) s[2] += sub;
      sort(s, s + 3);
      for (int i = 0; i < 3; i++) {
        if (s[i][0] != '0') {
          printf("%s\n", s[i].c_str());
          break;
        }
      }
    }
  }
}
