#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<int> num(10);
  for (int i = 0; i < n; i++) num[s[i] - '0']++;
  for (int i = 0; i < m; i++) num[t[i] - '0']--;
  for (int i = 1; i <= n; i++) {
    if (i + (int)log10(i) + 1 == s.size()) {
      for (int j = i; j > 0; j /= 10) num[j % 10]--;
    }
  }
  string u = t;
  u.erase(unique(u.begin(), u.end()), u.end());
  string ans = "~";
  int x = 10;
  for (int i = 9; i >= 1; i--) {
    if (num[i] > 0) x = i;
  }
  if (t[0] != '0') {
    string cand = t;
    for (int i = 0; i < 10; i++) cand += string(num[i], i + '0');
    ans = min(ans, cand);
  }
  if (x <= 9) {
    string prefix = string(1, x + '0');
    string suffix;
    num[x]--;
    for (int i = 0; i <= 9; i++) {
      if (i < t[0] - '0') {
        prefix += string(num[i], i + '0');
      } else if (i > t[0] - '0') {
        suffix += string(num[i], i + '0');
      } else {
        if (u.size() == 1 || u[0] > u[1]) {
          suffix += string(num[i], i + '0');
        } else {
          prefix += string(num[i], i + '0');
        }
      }
    }
    ans = min(ans, prefix + t + suffix);
  }
  if (ans == "~") ans = "0";
  cout << ans << endl;
}
