#include <bits/stdc++.h>
using namespace std;
string shuffled, substring, head, _back;
int cnt[11];
int k;
int main() {
  cin >> shuffled;
  cin >> substring;
  int n = shuffled.size();
  int temp = 1;
  for (int i = 1; i <= 7; i++) {
    temp *= 10;
    if (n - i <= temp - 1) {
      k = n - i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cnt[shuffled[i] - '0']++;
  }
  int cnt0 = 0;
  int ch0 = 0;
  for (int i = 0; i < substring.size(); i++) {
    cnt[substring[i] - '0']--;
    if (i > 0 && (substring[i] - '0')) ch0 = 1;
    if (!(substring[i] - '0') && !ch0) cnt0++;
  }
  int kk = k;
  while (kk) {
    cnt[kk % 10]--;
    kk /= 10;
  }
  for (char i = '0'; i <= '9'; i++) {
    if ((substring + i) < (i + substring)) {
      for (int j = 1; j <= cnt[i - '0']; j++) _back += i;
    } else {
      for (int j = 1; j <= cnt[i - '0']; j++) head += i;
    }
  }
  string preans = head + substring + _back;
  int possub = head.size();
  int endpos = substring.size() + head.size();
  if (preans[0] == '0' && preans.size() > 1) {
    for (int i = 0; i < k; i++) {
      if (cnt0 != (substring.size() - 1) && substring[0] == preans[endpos] &&
          i == possub) {
        if (head.size() >= cnt0) {
          cout << preans[endpos];
          cout << head << substring;
          for (int j = endpos + 1; j < k; j++) cout << preans[j];
          return 0;
        }
      } else if (preans[i] != '0' && i < possub) {
        cout << preans[i];
        for (int j = 0; j < head.size(); j++)
          if (j != i) {
            cout << head[j];
          }
        cout << substring << _back;
        return 0;
      } else if (preans[i] != '0' && i >= possub && i < endpos &&
                 substring[0] != '0') {
        cout << substring << head << _back;
        return 0;
      } else if (preans[i] != '0' && i >= endpos) {
        cout << preans[i];
        cout << head;
        cout << substring;
        for (int j = 0; j < _back.size(); j++)
          if (i != j + endpos) {
            cout << _back[j];
          }
        return 0;
      }
    }
  } else {
    cout << preans;
    return 0;
  }
}
