#include <bits/stdc++.h>
using namespace std;
string s, t;
int a[15], b[15], c[15];
bool check(int x) {
  int h = x;
  for (int i = 0; i <= 9; i++) {
    c[i] = a[i];
  }
  while (x) {
    c[x % 10]--;
    x /= 10;
  }
  for (int i = 0; i <= 9; i++) {
    if (c[i] < b[i]) return false;
  }
  int num = 0;
  for (int i = 0; i <= 9; i++) {
    num += c[i];
  }
  if (num != h) return false;
  int sum = 0;
  for (int i = 1; i <= 9; i++) {
    sum += c[i] - b[i];
  }
  if (sum == 0 && t[0] == '0' && x > 1) return false;
  return true;
}
int main() {
  cin >> s >> t;
  int pos = 1, tag = 0;
  for (int i = 0; i < s.length(); i++) {
    a[s[i] - '0']++;
  }
  for (int i = 0; i < t.length(); i++) {
    b[t[i] - '0']++;
  }
  while (true) {
    if (check(pos)) break;
    pos++;
  }
  for (int i = 0; i <= 9; i++) {
    c[i] -= b[i];
  }
  string ans = "";
  int x = 0;
  for (int i = 1; i <= 9; i++) {
    if (c[i]) {
      x = i;
      break;
    }
  }
  if (x != 0) {
    c[x]--, ans += (char)(x + '0');
    for (int i = 0; i <= 9; i++) {
      char k = (char)(i + '0');
      if (k < t[0] || tag == 1) {
        for (int j = 1; j <= c[i]; j++) {
          ans += k;
        }
      } else if (k == t[0] && tag == 0) {
        string l = "";
        for (int j = 1; j <= c[i]; j++) {
          l += (char)(i + '0');
        }
        ans += min(l + t, t + l);
        tag = 1;
      } else if (k > t[0] && tag == 0) {
        ans += t;
        tag = 1;
        for (int j = 1; j <= c[i]; j++) {
          ans += k;
        }
      }
    }
    if (t[0] == '0')
      cout << ans << endl;
    else {
      c[x]++;
      string ans1 = t;
      for (int i = 0; i <= 9; i++) {
        for (int j = 1; j <= c[i]; j++) {
          ans1 += (char)(i + '0');
        }
      }
      cout << min(ans, ans1) << endl;
    }
  } else {
    if (c[0] == 0) {
      cout << t << endl;
      return 0;
    } else {
      cout << t;
      for (int i = 1; i <= c[0]; i++) cout << "0";
    }
  }
}
